Using Python to debug C and C++ code (using gdb)

Got a difficult C/C++ program to debug? The power of Python is now available from within the GNU debugger. I'll show how you can use simple fragments of Python to quickly track down fiddly bugs in C/C++ code. We'll also see how to use Python to extend gdb with new commands and new ways of visualizing the internal state of a program.

Abstract

The GNU debugger, gdb, is the standard debugger when dealing with bugs in machine-code programs on Linux systems. As of gdb7 it supports a Python interface, allowing experienced Python programmers to extend the reach of the debugger. Difficult debugging tasks can be dramatically simplified by adding a little python.

I'm the author of two substantial bodies of gdb python code: pretty-printers for Python itself, and for the GNU libc implementation of "malloc/free".