From: Cyrill Gorcunov <gorcunov@gmail.com>
To: Pekka Enberg <penberg@kernel.org>
Cc: Ingo Molnar <mingo@elte.hu>, Asias He <asias.hejun@gmail.com>,
Sasha Levin <levinsasha928@gmail.com>,
Prasad Joshi <prasadjoshi124@gmail.com>,
kvm-vger <kvm@vger.kernel.org>
Subject: [PATCH] kvm tools: Add debug() helper
Date: Wed, 11 May 2011 20:10:51 +0400 [thread overview]
Message-ID: <4DCAB50B.9030605@gmail.com> (raw)
Useful for debugging. It adds "--debug" option as well so
debug prints are seen only if user asked for them.
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
---
No real users in code yet, the patches with debug()
are in stage, posted out to not loose it.
Thanks.
tools/kvm/Documentation/kvm-run.txt | 3 +++
tools/kvm/include/kvm/util.h | 10 ++++++++++
tools/kvm/kvm-run.c | 4 ++++
3 files changed, 17 insertions(+)
Index: linux-2.6.git/tools/kvm/Documentation/kvm-run.txt
=====================================================================
--- linux-2.6.git.orig/tools/kvm/Documentation/kvm-run.txt
+++ linux-2.6.git/tools/kvm/Documentation/kvm-run.txt
@@ -55,6 +55,9 @@ OPTIONS
--cpus::
The number of virtual CPUs to run.
+--debug::
+ Enable debug messages.
+
SEE ALSO
--------
linkkvm:
Index: linux-2.6.git/tools/kvm/include/kvm/util.h
=====================================================================
--- linux-2.6.git.orig/tools/kvm/include/kvm/util.h
+++ linux-2.6.git/tools/kvm/include/kvm/util.h
@@ -15,6 +15,7 @@
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
+#include <stdbool.h>
#include <errno.h>
#include <limits.h>
#include <sys/param.h>
@@ -29,6 +30,8 @@
#endif
#endif
+extern bool do_debug_print;
+
extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));
extern void die_perror(const char *s) NORETURN;
extern int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
@@ -36,6 +39,13 @@ extern void warning(const char *err, ...
extern void info(const char *err, ...) __attribute__((format (printf, 1, 2)));
extern void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN);
+#define debug(fmt, ...) \
+ do { \
+ if (do_debug_print) \
+ info("(%s) %s:%d: " fmt, __FILE__, \
+ __func__, __LINE__, ##__VA_ARGS__); \
+ } while (0)
+
#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
#define DIE_IF(cnd) \
Index: linux-2.6.git/tools/kvm/kvm-run.c
=====================================================================
--- linux-2.6.git.orig/tools/kvm/kvm-run.c
+++ linux-2.6.git/tools/kvm/kvm-run.c
@@ -66,6 +66,8 @@ static bool virtio_rng;
extern bool ioport_debug;
extern int active_console;
+bool do_debug_print = false;
+
static int nrcpus = 1;
static const char * const run_usage[] = {
@@ -126,6 +128,8 @@ static const struct option options[] = {
"Enable single stepping"),
OPT_BOOLEAN('g', "ioport-debug", &ioport_debug,
"Enable ioport debugging"),
+ OPT_BOOLEAN('\0', "debug", &do_debug_print,
+ "Enable debug messages"),
OPT_END()
};
reply other threads:[~2011-05-11 16:10 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4DCAB50B.9030605@gmail.com \
--to=gorcunov@gmail.com \
--cc=asias.hejun@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=levinsasha928@gmail.com \
--cc=mingo@elte.hu \
--cc=penberg@kernel.org \
--cc=prasadjoshi124@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox