debug.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * =====================================================================================
  3. *
  4. * .d8888b 88888b. .d88b. .d8888b 888d888 8888b. 88888b.d88b.
  5. * 88K 888 "88b d8P Y8b 88K 888P" "88b 888 "888 "88b
  6. * "Y8888b. 888 888 88888888 "Y8888b. 888 .d888888 888 888 888
  7. * X88 888 888 Y8b. X88 888 888 888 888 888 888
  8. * 88888P' 888 888 "Y8888 88888P' 888 "Y888888 888 888 888
  9. *
  10. * www.optixx.org
  11. *
  12. *
  13. * Version: 1.0
  14. * Created: 07/21/2009 03:32:16 PM
  15. * Author: david@optixx.org
  16. *
  17. * =====================================================================================
  18. */
  19. #include <stdlib.h>
  20. #include <stdint.h>
  21. #include "debug.h"
  22. #include "uart.h"
  23. extern FILE uart_stdout;
  24. extern int debug_level; /* the higher, the more messages... */
  25. #if defined(NO_DEBUG) && defined(__GNUC__)
  26. /* Nothing. debug has been "defined away" in debug.h already. */
  27. #else
  28. void debug(int level, char* format, ...) {
  29. #ifdef NO_DEBUG
  30. /* Empty body, so a good compiler will optimise calls
  31. to pmesg away */
  32. #else
  33. va_list args;
  34. if (!(debug_level & level))
  35. return;
  36. va_start(args, format);
  37. vprintf(format, args);
  38. va_end(args);
  39. #endif /* NDEBUG */
  40. #endif /* NDEBUG && __GNUC__ */
  41. }