enhanced gdbinit file - looking for Python+Emacs+gdb users

Skip Montanaro skip at pobox.com
Sun Nov 21 05:49:20 CET 2004

I got a little carried away with the gdbinit file that lives in the Python
distribution at Misc/gdbinit today.  I decided there's no particular reason
that gdb shouldn't display the current Python file when moving up and down
the C stack any time it encounters PyEval_EvalFrame.  After a little digging
I realized this would be pretty easy.  I made two changes to the gdbinit

    1. I wrote a lineno command for gdb that calculates and prints the
       current Python line number.  (It's PyCode_Addr2Line written in gdb's
       command language.)

    2. Using that and the current file gleaned from PyEval_EvalFrame I emit
       the file:line info in the correct format for Emacs to display the
       Python line number at the right time using overridden up and down

There's one slight hitch.  It works perfectly when travelling up the C stack
using the up command, however in my environment at least (MacOSX w/ Apple's
gcc and gdb) it causes gdb to segfault when travelling down the stack.  I
can't see anything that would make the behavior different going up instead
of down.  I need some people to try this thing out to see if it barfs for
them as well.  Maybe it's just something peculiar to my environment.  OTOH,
perhaps it's a bug in gdb.

Since I can't really check this beast in given its current rather dicey
behavior, I dropped a copy at


If you use Python with gdb via Emacs please give it a whirl and let me know
how it works for you.



P.S.  I think I know how to make the gdb print command print Python objects
as well...

More information about the Python-list mailing list