debug.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #ifndef __KERNEL_DEBUG_H
  2. #define __KERNEL_DEBUG_H
  3. void panic_spin(char *filename, int line, const char *func, const char *condition);
  4. /**
  5. * @brief panic 是一个宏,__VA_ARGS__ 表示可变参数,即 ...,用于传递参数
  6. * __VA_ARGS__ 是预处理器所支持的专用标识符。代表所有与省略号相对应的参数
  7. * “...” 表示定义的宏其参数可变
  8. */
  9. #define PANIC(...) panic_spin(__FILE__, __LINE__, __func__, __VA_ARGS__)
  10. #ifdef NDEBUG
  11. #define ASSERT(CONDITION) ((void)0)
  12. #else
  13. #define ASSERT(CONDITION) \
  14. if (CONDITION) \
  15. { \
  16. } \
  17. else \
  18. { \
  19. PANIC(#CONDITION); \
  20. }
  21. #endif // NDEBUG
  22. #ifdef UNUSED
  23. #elif defined(__GNUC__)
  24. #define UNUSED(x) UNUSED_##x __attribute__((unused))
  25. #elif defined(__clang__)
  26. #define UNUSED(x) _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wunused-parameter\"") \
  27. x _Pragma("clang diagnostic pop")
  28. #elif defined(__LCLINT__)
  29. #define UNUSED(x) /*@unused@*/ x
  30. #elif defined(_MSC_VER)
  31. #define UNUSED(x) __pragma(warning(push)) __pragma(warning(disable : 4101)) x __pragma(warning(pop)) // warning C4101: unreferenced local variable
  32. #elif defined(__ICC)
  33. #define UNUSED(x) x __attribute__((unused))
  34. #else
  35. #warning "Platform doesn't support attribute 'unused'"
  36. #define UNUSED(x) (void)x
  37. #endif // UNUSED
  38. #endif // __KERNEL_DEBUG_H