2024-01-26 21:58:02 +00:00
|
|
|
#ifndef CUTES_DEBUG_H
|
|
|
|
#define CUTES_DEBUG_H
|
2024-01-25 13:08:23 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
#include <assert.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern int g_debug_error_abort;
|
|
|
|
extern int g_debug_log_lvl;
|
|
|
|
|
2024-09-24 13:26:08 +00:00
|
|
|
#ifdef NDEBUG
|
|
|
|
|
|
|
|
#define LOG_INFO(...)
|
|
|
|
#define LOG_ERROR(...)
|
|
|
|
#define LOG_WARNING(...)
|
|
|
|
#define RETURN_ERROR(...)
|
|
|
|
#define RETURN_WARNING(...)
|
|
|
|
#define ASSERT_RETURN(...)
|
|
|
|
#define CHECK(...)
|
|
|
|
#define ASSERT_RETURN_WARN(...)
|
|
|
|
#define UNREACHABLE(...)
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2024-01-25 13:08:23 +00:00
|
|
|
#define LOG_INFO(...) do {\
|
|
|
|
if(g_debug_log_lvl < 3) break;\
|
|
|
|
printf("[%s:%d] INFO | ", __FILE__, __LINE__);\
|
|
|
|
printf(__VA_ARGS__);\
|
|
|
|
printf("\n");\
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define LOG_ERROR(...) do {\
|
|
|
|
if(g_debug_log_lvl >= 1) {\
|
|
|
|
printf("[%s:%d] ERROR | ", __FILE__, __LINE__);\
|
|
|
|
printf(__VA_ARGS__);\
|
|
|
|
printf("\n");\
|
|
|
|
fflush(stdout);\
|
|
|
|
}\
|
|
|
|
if(g_debug_error_abort != 0) abort();\
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define LOG_WARNING(...) do {\
|
|
|
|
if(g_debug_log_lvl < 2) break;\
|
|
|
|
printf("[%s:%d] WARNING | ", __FILE__, __LINE__);\
|
|
|
|
printf(__VA_ARGS__);\
|
|
|
|
printf("\n");\
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
|
|
|
#define RETURN_ERROR(__VALUE, ...) do {\
|
|
|
|
LOG_ERROR(__VA_ARGS__);\
|
|
|
|
return __VALUE;\
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define RETURN_WARNING(__VALUE, ...) do {\
|
|
|
|
LOG_WARNING(__VA_ARGS__);\
|
|
|
|
return __VALUE;\
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define ASSERT_RETURN(__ASSERT, __RETURN, ...) do {\
|
|
|
|
if(!(__ASSERT)) {\
|
|
|
|
LOG_ERROR(__VA_ARGS__);\
|
|
|
|
return __RETURN;\
|
|
|
|
}\
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define CHECK(__ASSERT, ...) do {\
|
|
|
|
if(!(__ASSERT)) {\
|
|
|
|
LOG_ERROR(__VA_ARGS__);\
|
|
|
|
}\
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define ASSERT_RETURN_WARN(__ASSERT, __RETURN, ...) do {\
|
|
|
|
if(!(__ASSERT)) {\
|
|
|
|
LOG_WARNING(__VA_ARGS__);\
|
|
|
|
return __RETURN;\
|
|
|
|
}\
|
|
|
|
} while(0)
|
|
|
|
|
2024-01-29 09:38:42 +00:00
|
|
|
#define UNREACHABLE(...) do {\
|
|
|
|
LOG_ERROR(__VA_ARGS__);\
|
2024-09-10 13:07:02 +00:00
|
|
|
abort();\
|
2024-01-29 09:38:42 +00:00
|
|
|
} while(0)
|
|
|
|
|
2024-09-24 13:26:08 +00:00
|
|
|
#endif
|
|
|
|
|
2024-01-26 21:58:02 +00:00
|
|
|
#endif // !CUTES_DEBUG_H
|