aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandru Elisei <alexandru.elisei@arm.com>2023-07-07 16:11:18 +0100
committerWill Deacon <will@kernel.org>2023-07-12 17:11:56 +0100
commitfc184a682a2164c156655ec18bc4a18bb638f644 (patch)
tree28716f54537ac06fe2a3c2eafceee82fc8653953
parent72e13944777a6c60fbcd78ef97e06ffd00969d77 (diff)
downloadkvmtool-fc184a682a2164c156655ec18bc4a18bb638f644.tar.gz
util: Use __pr_debug() instead of pr_info() to print debug messages
pr_debug() is special, because it can be suppressed with a command line argument, and because it needs to be a macro to capture the correct filename, function name and line number. Display debug messages with the prefix "Debug", to make it clear that those aren't informational messages. Reviewed-by: Jean-Philippe Brucker <jean-philippe@linaro.org> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com> Reviewed-by: Anup Patel <anup@brainfault.org> Link: https://lore.kernel.org/r/20230707151119.81208-4-alexandru.elisei@arm.com Signed-off-by: Will Deacon <will@kernel.org>
-rw-r--r--include/kvm/util.h3
-rw-r--r--util/util.c15
2 files changed, 17 insertions, 1 deletions
diff --git a/include/kvm/util.h b/include/kvm/util.h
index f51f370d..68d568d0 100644
--- a/include/kvm/util.h
+++ b/include/kvm/util.h
@@ -42,12 +42,13 @@ extern void die_perror(const char *s) NORETURN;
extern void pr_err(const char *err, ...) __attribute__((format (printf, 1, 2)));
extern void pr_warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
extern void pr_info(const char *err, ...) __attribute__((format (printf, 1, 2)));
+extern void __pr_debug(const char *debug, ...) __attribute__((format (printf, 1, 2)));
extern void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN);
#define pr_debug(fmt, ...) \
do { \
if (do_debug_print) \
- pr_info("(%s) %s:%d: " fmt, __FILE__, \
+ __pr_debug("(%s) %s:%d: " fmt, __FILE__, \
__func__, __LINE__, ##__VA_ARGS__); \
} while (0)
diff --git a/util/util.c b/util/util.c
index f59f26e1..7cf62edc 100644
--- a/util/util.c
+++ b/util/util.c
@@ -38,6 +38,11 @@ static void info_builtin(const char *info, va_list params)
report(" Info: ", info, params);
}
+static void debug_builtin(const char *debug, va_list params)
+{
+ report(" Debug: ", debug, params);
+}
+
void die(const char *err, ...)
{
va_list params;
@@ -74,6 +79,16 @@ void pr_info(const char *info, ...)
va_end(params);
}
+/* Do not call directly; call pr_debug() instead. */
+void __pr_debug(const char *debug, ...)
+{
+ va_list params;
+
+ va_start(params, debug);
+ debug_builtin(debug, params);
+ va_end(params);
+}
+
void die_perror(const char *s)
{
perror(s);