1. Installing a Python-enabled debugger

This is the first in what I hope will be a series on using the python-enabled gdb.

We’ll start at the very beginning: checking it out, building it, and then “hello, world”.

First, install the prerequisites — aside from the normal development stuff, you will need the python development packages.  You will also need git.  If you don’t have makeinfo installed, you will want that, too.  On Fedora you can get these with:

$ sudo yum install python-devel git texinfo

That was easy!  Now we will check out and build the gdb branch.  I like to prepare for this by making a new directory where I will keep the source, build, and install trees:

$ mkdir -p ~/archer/build ~/archer/install
$ cd ~/archer

“Archer” is the name of our project, in case you’re wondering.  Note that the clone step will take a while — it is downloading the entire history of gdb.  My source tree weighs in at about 50M.

$ git clone git://sourceware.org/git/archer.git
$ cd archer
$ git checkout --track -b python origin/archer-tromey-python

Now you have archer checked out and on the right branch.  If you’re curious, other work is being done in the Archer repository.  Currently each separate project has its own “topic branch”, but we’ll be merging them together for a release.  You can see the different topics with:

$ git branch -r | grep archer

This repository is also periodically synced from gdb.  For example you could look at the in-progress multi-process work — that is, patches to let gdb debug multiple processes at the same time — by checking out the branch gdb/multiprocess-20081120-branch.

Now build gdb.  Depending on your machine, this might take a while.

$ cd ../build
$ ../archer/configure --prefix=$(cd ../install && pwd)
$ make all install

(As an aside: I have typed that goofy --prefix line a million times.  I wish configure would just do that for me.)

Now you are ready to try your python-enabled gdb.  We’ll just add the right directory to your path and then do a smoke test for now; we’ll look at more functionality in the next installment.

$ PATH=~/archer/install/bin:$PATH
$ gdb
(gdb) python print 23
(gdb) quit

It worked!

Once you have this set up, future updates are even simpler — and faster.  Just pull and rebuild:

$ cd ~/archer/archer
$ git pull
$ cd ../build
$ make all install

We’re actively hacking on this branch, so you may like to do this regularly.  If you find bugs, feel free to email the Archer list.  (We’ll have bugzilla working “soon”, but for the time being just fire off a note.)

I think next time we will look at writing a new gdb command in Python.  Also, we’ll try a couple of new commands, written this way, that are shipped with the Python-enabled gdb.

In the future, it will be much simpler to get this gdb.  Like I said before, I want it to be in Fedora 11 (and yeah, making the feature page is on my to-do list; I’ll try to get to it next week).  Also, I think Daniel is making a Debian experimental package for it.

Update: fixed a bug in the checkout command.  Oops.

Share if you liked it


  • Shouldn’t the git checkout command after cloning be “$ git checkout –track -b python origin/archer-tromey-python”?

  • Thanks! I fixed it.

  • Not only doing but did. It went up just before you wrote this.

    The Python-enabled GDB is now available in Debian Experimental. I will be updating it periodically, but poke me if you want it refreshed. The source package builds on unstable and probably on testing, but likely not in Etch.

    Just add an experimental line to your sources.list file, and use the APT preferences file to prefer unstable for everything but GDB. There’s probably an easier way but I do not know it off the top of my head.

  • > (As an aside: I have typed that goofy –prefix line a million times. I wish configure would just do that for me.)

    I hope this comes out literally:

    cat >> ~/.bashrc <$CONFIG_SITE <<EOF
    test “$prefix” = NONE && prefix=$HOME/archer/install

  • OK, it didn’t, sigh, so I’ll just explain it. Use the line
    test “$prefix” = NONE && prefix=$HOME/archer/install

    in a config.site file. Put it either where configure will find it by default (/usr/local/share/config.site) or where you like. In the latter case, set
    $CONFIG_SITE appropriately.

  • What I really want is for configure to automatically absolute-ize a relative –prefix directory. I don’t see why it shouldn’t, really.

    Meanwhile, usually I just use a wrapper script.

  • I suggest linking to your blog posts from the pythong/gdb wiki page.

  • […] STL containers with GDB (Python enabled GDB) By turbosree The link explains how to install gdb archer on […]

  • First, thank you for your fantastic work! I believe this project will heavily change my process of debugging.

    But of course i have couple of technical questions 🙂
    Is it necessary to check out git repo? Is it equal to using usual gdb snapshots? If they differ, is there any place with git snapshots? (I work through proxy, so using external git repos doesn’t work for me.)
    Latest gdb python-enabled snapshot supports ‘python’ command, but does not know anything about commands from Python API, also there is no -P option in it.

  • The archer git repository has more Python bindings than gdb snapshots do. So, it really depends on what you want to do… We push things from the git repository to gdb CVS when we feel they are mature enough. This generally means that gdb CVS is a bit more API-stable, but OTOH less powerful.

    We merge from gdb CVS to the git branch periodically (last time 2 weeks ago, though I’m doing another merge today). So there usually isn’t too much difference.

    As to your last question, “gdb -P” is one of the features we haven’t upstreamed yet.

  • is there a windows ready python enabled gdb.exe available for download? it is very difficult to follow your steps in a windows environment, especially i don’t have to cygwin installed. thanks.

  • Nope, we don’t have windows builds ready. Sorry about that.

  • apt-get install python-dev libncurses5-dev make
    ./configure –prefix=/usr/local –with-python=python2 && make
    make -C gdb install

Join the Discussion

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>