summaryrefslogtreecommitdiff
path: root/shared/debug.h
diff options
context:
space:
mode:
Diffstat (limited to 'shared/debug.h')
-rw-r--r--shared/debug.h97
1 files changed, 49 insertions, 48 deletions
diff --git a/shared/debug.h b/shared/debug.h
index 6f1a054..2b1eba0 100644
--- a/shared/debug.h
+++ b/shared/debug.h
@@ -2,6 +2,7 @@
#define foodebughfoo
/* FIXME: Should these be shared? */
+/* clang-format off */
enum debug_lvl {
DBG_ERROR = (0x1 << 1),
DBG_INFO = (0x1 << 2),
@@ -21,70 +22,70 @@ enum debug_lvl {
DBG_DNS = (0x1 << 16),
DBG_TIMER = (0x1 << 17),
};
+/* clang-format on */
-static inline bool
-debug_enabled(enum debug_lvl lvl)
+static inline bool debug_enabled(enum debug_lvl lvl)
{
return !!(lvl & debug_mask);
}
-#define __ifdebug(lvl, fmt, ...) \
- do { \
- if (debug_enabled((lvl))) \
- __debug((lvl), fmt "\n"__VA_OPT__(,) __VA_ARGS__); \
+#define __ifdebug(lvl, fmt, ...) \
+ do { \
+ if (debug_enabled((lvl))) \
+ __debug((lvl), fmt "\n"__VA_OPT__(, )__VA_ARGS__); \
} while (0)
-#define debug(lvl, fmt, ...) __ifdebug((lvl), "%s:%s:%i: " fmt, \
- __FILE__, __func__, __LINE__ \
- __VA_OPT__(,) __VA_ARGS__)
-#define verbose(fmt, ...) __ifdebug(DBG_VERBOSE, fmt, __VA_ARGS__)
-#define info(fmt, ...) __ifdebug(DBG_INFO, fmt, __VA_ARGS__)
-#define error(fmt, ...) __ifdebug(DBG_ERROR, "%s:%s:%i: " fmt, \
- __FILE__, __func__, __LINE__ \
- __VA_OPT__(,) __VA_ARGS__)
+#define debug(lvl, fmt, ...) \
+ __ifdebug((lvl), "%s:%s:%i: " fmt, __FILE__, __func__, \
+ __LINE__ __VA_OPT__(, ) __VA_ARGS__)
+#define verbose(fmt, ...) __ifdebug(DBG_VERBOSE, fmt, __VA_ARGS__)
+#define info(fmt, ...) __ifdebug(DBG_INFO, fmt, __VA_ARGS__)
+#define error(fmt, ...) \
+ __ifdebug(DBG_ERROR, "%s:%s:%i: " fmt, __FILE__, __func__, \
+ __LINE__ __VA_OPT__(, ) __VA_ARGS__)
-#define die(fmt, ...) \
- __die("%s:%s:%i: " fmt "\n", \
- __FILE__, __func__, __LINE__ \
- __VA_OPT__(,) __VA_ARGS__)
+#define die(fmt, ...) \
+ __die("%s:%s:%i: " fmt "\n", __FILE__, __func__, \
+ __LINE__ __VA_OPT__(, ) __VA_ARGS__)
-#define assert_log(expr, msg) \
- ((expr) ? \
- (true) : \
- (__debug(DBG_ERROR, "%s:%s:%i: assertion \"" msg "\" failed\n", \
- __FILE__, __func__, __LINE__), false))
+#define assert_log(expr, msg) \
+ ((expr) ? (true) : \
+ (__debug(DBG_ERROR, \
+ "%s:%s:%i: assertion \"" msg "\" failed\n", \
+ __FILE__, __func__, __LINE__), \
+ false))
-#define assert_return(expr, ...) \
- do { \
- if (!assert_log(expr, #expr)) \
- return __VA_ARGS__; \
+#define assert_return(expr, ...) \
+ do { \
+ if (!assert_log(expr, #expr)) \
+ return __VA_ARGS__; \
} while (0)
-#define assert_return_silent(expr, ...) \
- do { \
- if (!(expr)) \
- return __VA_ARGS__; \
+#define assert_return_silent(expr, ...) \
+ do { \
+ if (!(expr)) \
+ return __VA_ARGS__; \
} while (0)
-#define assert_die(expr, msg) \
- do { \
- if (!assert_log(expr, #expr)) \
- die(msg); \
+#define assert_die(expr, msg) \
+ do { \
+ if (!assert_log(expr, #expr)) \
+ die(msg); \
} while (0)
-#define assert_task_alive_or(lvl, t, cmd) \
-do { \
- if (!(t)) { \
- error("invalid task"); \
- cmd; \
- } \
- \
- if ((t)->dead) { \
- debug((lvl), "task dead"); \
- cmd; \
- } \
-} while(0)
+#define assert_task_alive_or(lvl, t, cmd) \
+ do { \
+ if (!(t)) { \
+ error("invalid task"); \
+ cmd; \
+ } \
+ \
+ if ((t)->dead) { \
+ debug((lvl), "task dead"); \
+ cmd; \
+ } \
+ } while (0)
-#define assert_task_alive(lvl, t) assert_task_alive_or((lvl), (t), return)
+#define assert_task_alive(lvl, t) assert_task_alive_or((lvl), (t), return )
#endif