On 10/05/2017 06:18 PM, Doug Gale wrote: > I added the tracing output in this patch to assist me in implementing > an NVMe driver. It helped tremendously. > >>From 1d19086cdef8d492929852d582cb41dcc5026f71 Mon Sep 17 00:00:00 2001 > From: Doug Gale <doug...@gmail.com> > Date: Thu, 5 Oct 2017 19:02:03 -0400 > Subject: [PATCH] Add tracing output to NVMe emulation to help driver authors. > > It is off by default, enable it by uncommenting #define DEBUG_NVME > or through CFLAGS > > Signed-off-by: Doug Gale <doug...@gmail.com> > --- > hw/block/nvme.c | 191 > +++++++++++++++++++++++++++++++++++++++++++++++++++----- > 1 file changed, 177 insertions(+), 14 deletions(-) > > diff --git a/hw/block/nvme.c b/hw/block/nvme.c > index 9aa32692a3..74220c0171 100644 > --- a/hw/block/nvme.c > +++ b/hw/block/nvme.c > @@ -36,6 +36,14 @@ > > #include "nvme.h" > > +//#define DEBUG_NVME > + > +#ifdef DEBUG_NVME > +#define DPRINTF(fmt, ...) fprintf(stderr, "nvme: " fmt "\n", ## __VA_ARGS__) > +#else > +#define DPRINTF(fmt, ...) ((void)0) > +#endif
As Kevin said, using trace-events is nicer than fprintf(). But if you absolutely insist on fprintf(), then do NOT do it like this, because this leads to bit-rot. Instead, do it in a form that lets -Wformat checking work even when tracing is disabled: #ifdef DEBUG_NVME # define DEBUG_NVME_PRINT 1 #else # define DEBUG_NVME_PRINT 0 #endif #define DPRINTF(fmt, ...) \ do { \ if (DEBUG_NVME_PRINT) { \ fprintf(stderr, "nvme: " fmt "\n", ## __VA_ARGS__); \ } \ while (0) -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature