qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 14/43] usb: made printf always compile in debug


From: Samuel Thibault
Subject: Re: [Qemu-devel] [PATCH 14/43] usb: made printf always compile in debug output
Date: Sun, 2 Apr 2017 00:24:05 +0200
User-agent: NeoMutt/20170113 (1.7.2)

Danil Antonov, on sam. 01 avril 2017 16:48:58 +0300, wrote:
> From 02b1e378eea154c0169a3d16b64ae27c64919c2c Mon Sep 17 00:00:00 2001
> From: Danil Antonov <address@hidden>
> Date: Wed, 29 Mar 2017 12:28:51 +0300
> Subject: [PATCH 14/43] usb: made printf always compile in debug output
> 
> Wrapped printf calls inside debug macros (DPRINTF) in `if` statement.
> This will ensure that printf function will always compile even if debug
> output is turned off and, in turn, will prevent bitrot of the format
> strings.
> 
> Signed-off-by: Danil Antonov <address@hidden>

Acked-by: Samuel Thibault <address@hidden>

> ---
>  hw/usb/dev-serial.c  | 17 +++++++++--------
>  hw/usb/dev-storage.c | 17 +++++++++--------
>  hw/usb/hcd-ehci.h    | 10 +++++-----
>  hw/usb/hcd-xhci.c    | 19 ++++++++++++-------
>  4 files changed, 35 insertions(+), 28 deletions(-)
> 
> diff --git a/hw/usb/dev-serial.c b/hw/usb/dev-serial.c
> index 6d51373..739e79b 100644
> --- a/hw/usb/dev-serial.c
> +++ b/hw/usb/dev-serial.c
> @@ -17,14 +17,15 @@
>  #include "hw/usb/desc.h"
>  #include "sysemu/char.h"
>  
> -//#define DEBUG_Serial
> -
> -#ifdef DEBUG_Serial
> -#define DPRINTF(fmt, ...) \
> -do { printf("usb-serial: " fmt , ## __VA_ARGS__); } while (0)
> -#else
> -#define DPRINTF(fmt, ...) do {} while(0)
> -#endif
> +#ifndef DEBUG_Serial
> +#define DEBUG_Serial 0
> +#endif
> +
> +#define DPRINTF(fmt, ...) do {                              \
> +    if (DEBUG_Serial) {                                     \
> +        fprintf(stderr, "usb-serial: " fmt,## __VA_ARGS__); \
> +    }                                                       \
> +} while (0);
>  
>  #define RECV_BUF 384
>  
> diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
> index 8a61ec9..b85c006 100644
> --- a/hw/usb/dev-storage.c
> +++ b/hw/usb/dev-storage.c
> @@ -24,14 +24,15 @@
>  #include "qapi/visitor.h"
>  #include "qemu/cutils.h"
>  
> -//#define DEBUG_MSD
> -
> -#ifdef DEBUG_MSD
> -#define DPRINTF(fmt, ...) \
> -do { printf("usb-msd: " fmt , ## __VA_ARGS__); } while (0)
> -#else
> -#define DPRINTF(fmt, ...) do {} while(0)
> -#endif
> +#ifndef DEBUG_MSD
> +#define DEBUG_MSD 0
> +#endif
> +
> +#define DPRINTF(fmt, ...) do {                             \
> +    if (DEBUG_MSD) {                                       \
> +        fprintf(stderr, "usb-msd: " fmt , ## __VA_ARGS__); \
> +    }                                                      \
> +} while (0);
>  
>  /* USB requests.  */
>  #define MassStorageReset  0xff
> diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h
> index 938d8aa..ca6094e 100644
> --- a/hw/usb/hcd-ehci.h
> +++ b/hw/usb/hcd-ehci.h
> @@ -30,11 +30,11 @@
>  #define EHCI_DEBUG   0
>  #endif
>  
> -#if EHCI_DEBUG
> -#define DPRINTF printf
> -#else
> -#define DPRINTF(...)
> -#endif
> +#define DPRINTF(fmt, ...) do {                \
> +    if (EHCI_DEBUG) {                         \
> +        fprintf(stderr, fmt, ## __VA_ARGS__); \
> +    }                                         \
> +} while (0);
>  
>  #define MMIO_SIZE        0x1000
>  #define CAPA_SIZE        0x10
> diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
> index f0af852..9f5e5b2 100644
> --- a/hw/usb/hcd-xhci.c
> +++ b/hw/usb/hcd-xhci.c
> @@ -32,11 +32,16 @@
>  //#define DEBUG_XHCI
>  //#define DEBUG_DATA
>  
> -#ifdef DEBUG_XHCI
> -#define DPRINTF(...) fprintf(stderr, __VA_ARGS__)
> -#else
> -#define DPRINTF(...) do {} while (0)
> -#endif
> +#ifndef DEBUG_XHCI
> +#define DEBUG_XHCI 0
> +#endif
> +
> +#define DPRINTF(fmt, ...) do {                 \
> +    if (DEBUG_XHCI) {                          \
> +        fprintf(stderr, fmt , ## __VA_ARGS__); \
> +    }                                          \
> +} while (0);
> +
>  #define FIXME(_msg) do { fprintf(stderr, "FIXME %s:%d %s\n", \
>                                   __func__, __LINE__, _msg); abort(); } while
> (0)
>  
> @@ -1806,7 +1811,7 @@ static int xhci_setup_packet(XHCITransfer *xfer)
>          ep = xhci_epid_to_usbep(xfer->epctx);
>          if (!ep) {
>              DPRINTF("xhci: slot %d has no device\n",
> -                    xfer->slotid);
> +                    xfer->epctx->slotid);
>              return -1;
>          }
>      }
> @@ -1980,7 +1985,7 @@ static int xhci_submit(XHCIState *xhci, XHCITransfer
> *xfer, XHCIEPContext *epctx
>  {
>      uint64_t mfindex;
>  
> -    DPRINTF("xhci_submit(slotid=%d,epid=%d)\n", xfer->slotid, xfer->epid);
> +    DPRINTF("xhci_submit(slotid=%d,epid=%d)\n", xfer->epctx->slotid, xfer->
> epctx->epid);
>  
>      xfer->in_xfer = epctx->type>>2;
>  
> --
> 2.8.0.rc3
> 
> 
> References:
> 
> [1] mailto:address@hidden
> [2] mailto:address@hidden

-- 
Samuel
c> [ ] morning [ ] afternoon [ ] evening [ ] night , everyone (choose as 
applicable)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]