On micro controllers it is common to debug code using UART, as hardware breakpoints have many drawbacks.
This is a simple macro that has proven very useful:
#define DEBUG_OUT(value) sprintf(uartTxBuf, "%s = 0x%04X\n", #value, value);\
puts_UART((uint16_t *) uartTxBuf)
Usage example:
for (i=0; i < 4; i++)
{
DEBUG_OUT(i);
DEBUG_OUT(i % 3);
}
Recieved stream:
i = 0x0000
i % 3 = 0x0000
i = 0x0001
i % 3 = 0x0001
i = 0x0002
i % 3 = 0x0002
i = 0x0003
i % 3 = 0x0000
Yes, it's crude and unsafe. It's only applied until the bug is isolated, so this macro does no harm.