Reputation: 33
I am trying to compile gdb with python support so I can use the PrettyPrinters provided at : http://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python
I downloaded the latest gdb source from (http://ftp.gnu.org/gnu/gdb/gdb-7.6.1.tar.gz) and compiled it on my Centos 6.4 as follows: 1. ./configure --with-python 2. make
Do I need to provide a path or another argument to --with-python with the path to python libs or executable?
After compilation when I run gdb, I see this warning:
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.
The exception is obvious here and whatever I am going to do next is going to fail because it needs the gdb module, but I gave it a try anyways. So I added the following lines to ~/.gdbinit:
import sys
sys.path.insert(0, '/tmp/pretty/python')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
Now when I start gdb, I get this error:
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.
Can someone help me resolve this issue?
Upvotes: 3
Views: 11953
Reputation: 421
I think you need to upgrade your OS version. I encountered this problem after I updated glibc solely. As far as I know,in other cases,old release OS could cause this problem, e.g. Ubuntu 14.04.
Upvotes: 0
Reputation: 101
If anyone is stumbling upon this post trying to compile Python and GDB in Solus 4.1, please read the following setup guide created by me (Obviously swap out any directory names/trees to your own ones)
Set up .profile like this:
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
Set up .bashrc
like this
#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
Compile Python (debug build + dev (--enable-shared
is equivalent to python3-dev)) (create the "out" directory first - then run both commands from it)
../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
After compiling Python, you can start compiling GDB. set these flags before running the "configure" command (before compiling)
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"
Note down the path to compiled Python binary. You need to pass this path to GDB configure script
/home/jeremi-solus/Applications/Python-3.9.1/out/bin/python3.9
Run configure script like this - make sure you don't close the bash shell after exporting the earlier set values!! Also, make sure earlier set .profile
vars are set by running source ~/.bashrc
./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
Make GDB (run this from the out directory)
make
Start GDB with this command
./gdb -data-directory ./data-directory
Upvotes: 1
Reputation: 394
Check the permissions of /usr/local/share/gdb/python. Even after "make install" I had
drwxrwx--- 4 root root 4096 Mar 16 08:46 /usr/local/share/gdb
After setting them to go+rx recursively for it and all it's subdirectories the warning disappeared.
Upvotes: 0
Reputation: 22519
The CentOS 6 gdb already has Python support. So you don't really need to build your own.
However, since you did, did you try doing what gdb suggested in the error message?
Also, did you "make install"? You have to do that for it to work properly.
Finally, I'd be surprised if CentOS 6 did not already include the libstdc++ pretty-printers.
Upvotes: 0