2

I am trying to install GDB7.8 with Python support. From the source folder, I am running ./configure --with-python When I did tab-complete from --with- I did not see Python in the list. But when I ran configure with that flag, it did not baulk.

When I run make, it complains that Python is not found.

checking for python2.7... no

but Python is installed:

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

$ which python2.7 
/usr/bin/python2.7

I compiled GDB without --with-python and things installed without error. I was under the impression that GDB7.8 had Python support without the need for special flags. But when I run:

$gdb python
(gdb) run test.py

I get some sort of cannot import gdb Import error

So then I tried calling "pi":

(gdb) pi printf.py
Python scripting is not supported in this copy of GDB.

So... how do I get Python support in GDB7.8? is it actually not supported? Or should I not call "pi"?

3
  • 1
    Do sh -x ./configure --with-python and keep the output. Look for how configure handles --with-*, and look at the Makefile to see how it checks for python2.7. Could it need the python2.7 source?
    – waltinator
    Aug 20, 2014 at 3:14
  • 2
    Did you install the Python development files too? sudo apt-get install python-dev
    – Timo
    Aug 20, 2014 at 10:25
  • docs.python.org/devguide/gdb.html
    – j0h
    Feb 20, 2015 at 18:51

2 Answers 2

11

I spent quite a bit of time working on getting gdb (7.9) to work with Python (2.7). In the end everything worked rather well. However, there are a bunch of things that you have to get right. The key point is that the gdb configure script tries to compile a small C program that looks like this.

#include "Python.h"
int
main ()
{
Py_Initialize ();
  ;
  return 0;
}

If this program won't compile, then Python support won't be built. For this program to compile, the Python.h include file must be found in /usr/include/python2.7. This file will only exist if the python-devel package is installed. On my system (redhat), the command for installing this package is sudo yum install python-devel.

However, that's not enough to get Python installed. Before the configure script tries to compile the C program, it gets various options from python-config.py. If these options aren't correct, then the C program won't compile. On my system, python-config.py returned the options below.

-lpthread -ldl -lutil -lm -lpython2.7 -Xlinker -export-dynamic

These options didn't cause any problems in my environment. Other folks have had problems with the options returned from python-config.py and have made changes to python-config.py to resolve these problems. On my system the complete compile command was

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

This compile command completed without any errors as soon as I installed python-devel. Note you don't have to manually enter the gcc command. I did run the gcc command several times to make sure everything was correct. Normally, the configure script will run the compiler for you. Also note that to get the overall gdb install process to complete, makeinfo also had to be installed. The command for installing makeinfo was sudo yum install texinfo.

Overall, the correct set of steps seems to be

  1. Install python-devel

  2. Install texinfo

  3. Download the gdb source and gunzip it and untar it.

  4. cd to the gdb-7.9 directory with the configure file.

  5. ./configure --prefix=/usr --with-python
    make 
    sudo make install
    

It should be possible to get gdb to work with Python 3. The various gdb scripts and install programs mention Python 3 in many, many places. However, the correct procedure for installing gdb with Python 3 is unknown to me at this point.

0
2

With benefit of Peter Schaeffer's excellent answer, I was able to build & install GDB 8.3.1 with Python 3.6, from source. The critical insight was that the LDFLAGS and LIBS which ./configure accepts are different from the LDFLAGS and LIBS which make requires. Yes they should be same, but in this case they were not.


Pre-requisite Steps

  1. install python3 package

  2. install python3-devel package

  3. install texinfo package

  4. run /usr/bin/python3.6-config --includes; that printed (twice!)

    -I/usr/include/python3.6m
    
  5. run /usr/bin/python3.6-config --ldflags; that printed

    -L/usr/lib64 -lpython3.6m -lpthread -ldl -lutil -lm -Xlinker -export-dynamic
    
  6. run /usr/bin/python3.6-config --libs; that printed

    -lpython3.6m -lpthread -ldl -lutil -lm 
    
  7. find the real path of "python3" binary, by running readlink --canonicalize-existing $(which python3); that printed

    /usr/bin/python3.6
    

Build Steps

export CFLAGS="-I/usr/include/python3.6m"
export LDFLAGS="-L/usr/lib64"
export LIBS="-lpython3"

readonly configureOptions="\
--disable-ada \
--disable-cloog-version-check \
--disable-gdbmi \
--disable-host-shared \
--disable-isl-version-check \
--disable-libssp \
--disable-libquadmath \
--disable-libquadmath-support \
--disable-objc-gc \
--disable-source-highlight \
--disable-stage1-checking \
--disable-static-libjava \
--disable-tui \
--disable-werror \
--enable-stage1-languages=c,c++ \
--enable-vtable-verify \
--with-python=/usr/bin/python3.6 \
--with-static-standard-libraries \
--with-system-zlib \
--without-cloog \
--without-guile \
--without-isl \
--without-mpfr \
"
./configure $configureOptions

export LDFLAGS="-L/usr/lib64 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic"
export LIBS="-lpython3.6m -lpthread -ldl -lutil -lm"

make

make install

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .