Skip to content
Oleg Hahm edited this page Jul 10, 2014 · 5 revisions

Using gdb

Some boards provide a JTAG interface, which makes it feasible to perform live debugging via gdb. These platforms usually provide an additional target in the Makefile system called debug, so that simply calling make debug should start a debugging session. Sometime this starts only a remote target to be used with gdb as explained, for example, here for the IoT-LAB_M3.

Using printf

On other platforms, such as the MSB-A2, or when you don't have physical access to the JTAG interface, there's no other possibility to debug your code than using printf-debugging. In order to help you with that RIOT provides the macros DEBUG and DEBUGF that can be enabled on a per file basis, by adding something like this at the beginning of the file:

#define ENABLE_DEBUG  (1)
#include "debug.h"

You will find this pattern already in several RIOT files. When ENABLE_DEBUG is set to a positive value, DEBUG is a simple replacement for printf(), while DEBUGF adds the information about the file and line number to the beginning of the output. When building with DEVELHELP the macros additionally check if the stack size of the currently running thread is big enough to call printf.

If ENABLE_DEBUG is set to zero, the macros are ignored.

Please note: As written, this kind of debugging works intentionally only per file. You have to define ENABLE_DEBUG in every file you want to debug.