From 9eeffbeab84e71bd0a4cc0855cb1f72ad1849ba6 Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Tue, 16 Jun 2020 13:15:33 +0200 Subject: Some more debug cleanups --- main.h | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'main.h') diff --git a/main.h b/main.h index 255a252..a794f6b 100644 --- a/main.h +++ b/main.h @@ -27,17 +27,26 @@ debug_enabled(enum debug_category category) return !!(category & debug_mask); } -void do_debug(enum debug_category category, const char *fmt, ...); - -#define __debug(c, ...) do { if (debug_enabled((c))) do_debug((c), __VA_ARGS__); } while (0) -#define debug(c, fmt, ...) __debug(c, "%s:" fmt, __func__, __VA_ARGS__) -#define verbose(...) __debug(DBG_VERBOSE, __VA_ARGS__) -#define info(...) __debug(DBG_ERROR, __VA_ARGS__) -#define error(...) __debug(DBG_ERROR, __VA_ARGS__) - -void die(const char *fmt, ...); - -#define perrordie(msg) die("%s: %m\n", msg) +void __debug(enum debug_category category, const char *fmt, ...) __attribute__((format(printf, 2, 3))); + +#define __ifdebug(c, fmt, ...) \ + do { \ + if (debug_enabled((c))) \ + __debug((c), fmt __VA_OPT__(,) __VA_ARGS__); \ + } while (0) + +#define debug(c, fmt, ...) __ifdebug((c), "%s:%i: " fmt, __func__, \ + __LINE__, __VA_ARGS__) +#define verbose(fmt, ...) __ifdebug(DBG_VERBOSE, fmt, __VA_ARGS__) +#define info(fmt, ...) __ifdebug(DBG_ERROR, fmt, __VA_ARGS__) +#define error(fmt, ...) __ifdebug(DBG_ERROR, fmt, __VA_ARGS__) + +void __die(const char *fmt, ...) __attribute__((format(printf, 1, 2))); + +#define die(fmt, ...) __die("%s:%i: " fmt "\n", __func__, \ + __LINE__ __VA_OPT__(,) __VA_ARGS__) +#define perrordie(fmt, ...) __die("%s:%i: " fmt ": %m\n", __func__, \ + __LINE__ __VA_OPT__(,) __VA_ARGS__) struct uring_task; -- cgit v1.2.3