Debugging Bongo agents

A quick debugging guide

First and foremost, in order to debug part of Bongo effectively, you need a debug build. In general, packaged Bongo isn't suitable for this.

Compiling from source, I often start like this:
CFLAGS="-ggdb -O0" ./autogen.sh --prefix=/tmp/bongo-build

You can set the build anywhere; I generally put testing builds in /tmp/ just because it's self-contained and I can install as my user - I don't need to be root. The CFLAGS part is important, though - you need "-ggdb" to include the debugging information in the binaries. Without this, you'll find it impossible to debug them effectively.

Debugging Agents

Agents are the simplest thing to debug. However, they do need "infrastructure" running. In particular, they need to be able to access the MDB configuration and server, and the store.

Usually, I will start by running "bongo-manager" in a terminal, on it's own, without allowing it to daemonize.

Once this is running, you should stop the agent you intend to debug (you can obviously skip this step if your agent is crashing ;). I usually "pkill bongosmtp" (change the agent name to suit).

Now you have bongo-manager running, but not the agent you want to debug. Now you can start debugging:

gdb /tmp/bongo-build/sbin/bongosmtp

Various gdb tips

Ideally, you need to know how to drive gdb. But as a quick overview, you basically type in commands at the prompt to control the program:

  1. break name - set a breakpoint at function name()
  2. r - run the program
  3. n - run the next instruction / function
  4. s - run and step into the next instruction / function (if you're in a breakpoint)
  5. print var - output the value contained in var
  6. c - continue normal execution after a break
  7. bt - print the stack trace; very useful after a crash