This took me a little while to work out, and will probably be useful in the future so I thought I’d make a post about it and use my blog for the first time in a year and a half ;)

  1. Download the ejabberd source:

    git clone https://github.com/processone/ejabberd.git
  2. Configure (I want ODBC support, but you might not need it)

    cd ejabberd && ./configure --enable-odbc
  3. Compile code with debugging enabled

    make debug=true
  4. Install ejabberd; I couldn’t work out if there was a way to run ejabberd without installing it.

    sudo make install
  5. Configure ejabberd as required by editing /etc/ejabberd/ejabberd.cfg. Then run it with

    sudo ejabberdctl start
  6. Attach to the running erlang process

    sudo ejabberdctl debug
  7. Press any key to continue. Then in the shell type:

    im().

This will open up the lovely erlang debugger monitor window, as shown below.

Erlang debugger

Then go to Module -> Interpret and browse to the ejabberd source code folder from earlier, and choose the .erl file you want to debug. This only works if the beam files have been compiled with debugging enabled, using the make step from before. Once you’ve selected a file, it will appear in the list on the left and you can double click it to view it and add break points as shown below.

mod_muc_room

To trigger the break point you just need to join a chat room with a client:

[caption id=”attachment_216” align=”aligncenter” width=”583” caption=”Break point triggered”]Break point triggered[/caption]

You can then step through the code by double clicking on the line with the break in it:

[caption id=”attachment_217” align=”aligncenter” width=”337” caption=”Step through debugging”]Step through debugging[/caption]

Happy debugging!