diff mbox

[v3,01/16] include/qemu-common.h: Add QEMU_DPRINTF macro

Message ID 1400367823-32610-2-git-send-email-marc.mari.barcelo@gmail.com
State New
Headers show

Commit Message

Marc Marí May 17, 2014, 11:03 p.m. UTC
Create this macro to let debug macros to have the same format through the
codebase and use regular ifs instead of ifdef.

Signed-off-by: Marc Marí <marc.mari.barcelo@gmail.com>
---
 include/qemu-common.h |    7 +++++++
 1 file changed, 7 insertions(+)

Comments

Eric Blake May 19, 2014, 3:28 p.m. UTC | #1
On 05/17/2014 05:03 PM, Marc Marí wrote:
> Create this macro to let debug macros to have the same format through the
> codebase and use regular ifs instead of ifdef.
> 
> Signed-off-by: Marc Marí <marc.mari.barcelo@gmail.com>
> ---
>  include/qemu-common.h |    7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/include/qemu-common.h b/include/qemu-common.h
> index 3f3fd60..acdcf08 100644
> --- a/include/qemu-common.h
> +++ b/include/qemu-common.h
> @@ -463,3 +463,10 @@ int parse_debug_env(const char *name, int max, int initial);
>  const char *qemu_ether_ntoa(const MACAddr *mac);
>  
>  #endif
> +
> +#define QEMU_DPRINTF(cond,pfx,fmt,...) \

Style: space after comma:
#define QEMU_DPRINTF(cond, pfx, fmt, ...) \

> +    do { \

Up to you if you want to align \ rather than putting them flush to each
line (I don't know if there is a prevalent style in the codebase).

> +        if (cond) { \
> +            fprintf(stderr, pfx": %s:"fmt, __func__, ## __VA_ARGS__); \

Style: spaces between string concatenation:

pfx ": %s:" fmt

This  definition requires that pfx and fmt be constant strings to allow
string concatenation.  Might it be better to allow for non-constants, by
splitting it into two actions, as in:

fprintf(stderr, "%s: %s:", pfx, __func__);
fprintf(stderr, fmt, ## __VA_ARGS__);
diff mbox

Patch

diff --git a/include/qemu-common.h b/include/qemu-common.h
index 3f3fd60..acdcf08 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -463,3 +463,10 @@  int parse_debug_env(const char *name, int max, int initial);
 const char *qemu_ether_ntoa(const MACAddr *mac);
 
 #endif
+
+#define QEMU_DPRINTF(cond,pfx,fmt,...) \
+    do { \
+        if (cond) { \
+            fprintf(stderr, pfx": %s:"fmt, __func__, ## __VA_ARGS__); \
+        } \
+  } while (0)