#include <stdio.h>
#include <stdarg.h>
#define config_ENABLE_DEBUG_MAIN 1
static char txBuffer[ 100 ] ;
void PrintDebug( char * fileName, int lineNumber, char * msg, ...) {
// NOTE: Replace all printf() calls in here with whatever is appropriate for
// the microcontroller you are using, e.g. Uart_PutString(txBuffer);
// Create "header" of debug message and send to UART peripheral
snprintf ( txBuffer
, sizeof ( txBuffer
) , "%s, %i: " , fileName
, lineNumber
) ;
// Format the "guts" of the debug message into a string
va_list args;
vsnprintf( txBuffer, sizeof ( txBuffer) , msg, args) ;
// Send formatted "guts" to the UART peripheral
}
#if(config_ENABLE_DEBUG_MAIN == 1)
#define DEBUG(...) PrintDebug(__FILE__, __LINE__, __VA_ARGS__)
#else
#define DEBUG(...)
#endif
int main( void ) {
DEBUG( "Testing debug print capabilities..." ) ;
DEBUG( "This should print both the filename and line number!" ) ;
int x = 5 ;
DEBUG( "We can also use this like printf()! x = %i" , x) ;
return 0 ;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRhcmcuaD4KCiNkZWZpbmUgY29uZmlnX0VOQUJMRV9ERUJVR19NQUlOIAkJMQoKc3RhdGljIGNoYXIgdHhCdWZmZXJbMTAwXTsKCnZvaWQgUHJpbnREZWJ1ZyhjaGFyICogZmlsZU5hbWUsIGludCBsaW5lTnVtYmVyLCBjaGFyICogbXNnLCAuLi4pIHsKCgkvLyBOT1RFOiBSZXBsYWNlIGFsbCBwcmludGYoKSBjYWxscyBpbiBoZXJlIHdpdGggd2hhdGV2ZXIgaXMgYXBwcm9wcmlhdGUgZm9yCgkvLyB0aGUgbWljcm9jb250cm9sbGVyIHlvdSBhcmUgdXNpbmcsIGUuZy4gVWFydF9QdXRTdHJpbmcodHhCdWZmZXIpOwoJCgkvLyBDcmVhdGUgImhlYWRlciIgb2YgZGVidWcgbWVzc2FnZSBhbmQgc2VuZCB0byBVQVJUIHBlcmlwaGVyYWwKCXNucHJpbnRmKHR4QnVmZmVyLCBzaXplb2YodHhCd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