From patchwork Fri Jun 30 13:31:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Elisei X-Patchwork-Id: 13298231 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7BA16EB64DA for ; Fri, 30 Jun 2023 13:32:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232622AbjF3NcB (ORCPT ); Fri, 30 Jun 2023 09:32:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232598AbjF3Nb5 (ORCPT ); Fri, 30 Jun 2023 09:31:57 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 30A041FD2 for ; Fri, 30 Jun 2023 06:31:56 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 96FB41063; Fri, 30 Jun 2023 06:32:39 -0700 (PDT) Received: from monolith.localdoman (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4CACB3F64C; Fri, 30 Jun 2023 06:31:54 -0700 (PDT) From: Alexandru Elisei To: will@kernel.org, julien.thierry.kdev@gmail.com, Suzuki.Poulose@arm.com, andre.przywara@arm.com, maz@kernel.org, oliver.upton@linux.dev, jean-philippe.brucker@arm.com, apatel@ventanamicro.com, kvm@vger.kernel.org Subject: [PATCH RESEND kvmtool 3/4] util: Use __pr_debug() instead of pr_info() to print debug messages Date: Fri, 30 Jun 2023 14:31:33 +0100 Message-ID: <20230630133134.65284-4-alexandru.elisei@arm.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230630133134.65284-1-alexandru.elisei@arm.com> References: <20230630133134.65284-1-alexandru.elisei@arm.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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. Signed-off-by: Alexandru Elisei Reviewed-by: Jean-Philippe Brucker --- include/kvm/util.h | 3 ++- util/util.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/kvm/util.h b/include/kvm/util.h index f51f370d2b37..6920ce2630ad 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 *err, ...) __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 f59f26e1581c..e3b36f67f899 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 *info, va_list params) +{ + report(" Debug: ", info, 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 *info, ...) +{ + va_list params; + + va_start(params, info); + debug_builtin(info, params); + va_end(params); +} + void die_perror(const char *s) { perror(s);