G+: Was looking into a way of debugging already-running …

David Coles
Was looking into a way of debugging already-running Python programs and stumbled across this feature. Turns out gdb 7 has Python scripting support and some wonderful folks have added support for Python introspection. This means you can fire up gdb on the recalcitrant process and `py-bt` to get a nice Python backtrace. It'll also pretty-print Python objects if you inspect them in the debugger.

On Debian/Ubuntu just install the `python-dbg` package.
Sadly on Ubuntu 13.10 there is a bug <https://bugs.launchpad.net/ubuntu/+source/gdb/+bug/1241668> where gdb is linked against libpython3.3 even though the scripts only supports Python 2.x. Whoops.

23. gdb Support — Python Developer's Guide

(+1's) 4
David Coles
I've added a quick patch for Python 3 support, so you can use this with Ubuntu 13.10.

David Coles
Urgh. Ok, maybe not quite so simple. I'd forgotten how much a pain in the arse Python2/3 compatible code is when working with bytes, string and unicode.