Skip to content

Category Archives: gdb

The GNU debugger

import gdb

Occasionally I see questions about how to import gdb from the ordinary Python interpreter.  This turns out to be surprisingly easy to implement. First, a detour into PIE and symbol visibility. “PIE” stands for “Position Independent Executable”.  It uses essentially the same approach as a shared library, except it can be applied to the executable.  […]

Quick Multi-process Debugging Update

In my last post I mentioned that setting breakpoints is a pain when debugging multiple processes in GDB. While there are some bugs here (we’re actively working on them), it isn’t hard to make the basic case work.  In fact, there’s nothing to it.  Some background… Starting with GDB 7.4, we changed how basic breakpoint […]

Debugging multiple programs at once

Consider this Makefile: all: runit runit: crasher ./crasher crasher: crasher.c gcc -g -o crasher crasher.c And, here is the program it is building: int *x = 0; int main () { *x = 52; } Now, if you run “make“, eventually you will see a crash.  But how to debug the crash? Well, obviously, this […]

Valgrind and GDB

Valgrind 3.7.0 now includes an embedded gdbserver, which is wired to the valgrind innards in the most useful way possible.  What this means is that you can now run valgrind in a special mode (simply pass –vgdb-error=0), then attach to it from gdb, just as if you were attaching to a remote target.  Valgrind will […]

13. Breakpoints

Phil Muldoon added support for breakpoints to the Python API in gdb this past year.  While work here is ongoing, you can already use it to do neat things which can’t be done from the gdb CLI. The interface to breakpoints is straightforward.  There is a new Breakpoint class which you can instantiate.  Objects of […]

12. Events

There have been many new Python scripting features added to gdb since my last post on the topic.  The one I want to focus on today is event generation. I wrote a little about events in gdb-python post #9 — but a lot has changed since then.  A Google SoC student, Oguz Kayral, wrote better […]

sys/sdt.h

Here’s a homework problem for you: design a static probe point API that: Consists of a single header file, Works for C, C++, and assembly, Allows probes to have arguments, Does not require any overhead for computing the arguments if they are already live, Does not require debuginfo for debug tools to extract argument values, […]

11. The End

We’ve covered many of the features of python-gdb: Writing new commands Convenience functions Pretty-printing Auto-loading of Python code Scripting gdb from Python Bringing up a GUI In fact, that is probably all of the user-visible things right now.  There are classes and methods in the Python API to gdb that we have not covered, but […]

10. Wacky stuff

Last time I promised something flashy in this post.  What could be flashier than a GUI? Here’s some code to get you started: from threading import Thread import gtk def printit (): print “Hello hacker” class TestGtkThread (Thread): def destroy (self, *args): self.window.hide() def hello (self, *args): gdb.post_event (printit) def run (self): gtk.gdk.threads_init() self.window = […]

9. Scripting gdb

So far we’ve concentrated on way to use Python to extend gdb: writing new commands, writing new functions, and customized pretty-printing.  In this post I want to look at gdb from a different angle: as a library.  I’ve long thought it would be pretty useful to be able to use gdb as a kind of […]