diff mbox

[RFC,19/19] target-unicore32: Refactor debug output macros

Message ID 1359293537-8251-20-git-send-email-afaerber@suse.de
State New
Headers show

Commit Message

Andreas Färber Jan. 27, 2013, 1:32 p.m. UTC
Make debug output compile-testable even if disabled.

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 target-unicore32/helper.c  |   12 ++++++------
 target-unicore32/softmmu.c |   12 ++++++------
 2 Dateien geändert, 12 Zeilen hinzugefügt(+), 12 Zeilen entfernt(-)

Comments

Guan Xuetao Jan. 29, 2013, 9:23 a.m. UTC | #1
> -----邮件原件-----
> 发件人: Andreas Färber [mailto:afaerber@suse.de]
> 发送时间: Sunday, January 27, 2013 21:32
> 收件人: qemu-devel@nongnu.org
> 抄送: Andreas Färber; Guan Xuetao (maintainer:UniCore32)
> 主题: [RFC 19/19] target-unicore32: Refactor debug output macros
> 
> Make debug output compile-testable even if disabled.
> 
> Signed-off-by: Andreas Färber <afaerber@suse.de>

The patch could work, but I don't think it's a good idea.
Perhaps tracetools can be better.

Guan Xuetao

> ---
>  target-unicore32/helper.c  |   12 ++++++------
>  target-unicore32/softmmu.c |   12 ++++++------
>  2 Dateien geändert, 12 Zeilen hinzugefügt(+), 12 Zeilen entfernt(-)
> 
> diff --git a/target-unicore32/helper.c b/target-unicore32/helper.c index
> 5359538..688c985 100644
> --- a/target-unicore32/helper.c
> +++ b/target-unicore32/helper.c
> @@ -17,13 +17,13 @@
>  #include "ui/console.h"
>  #endif
> 
> -#undef DEBUG_UC32
> +#define DEBUG_UC32 0
> 
> -#ifdef DEBUG_UC32
> -#define DPRINTF(fmt, ...) printf("%s: " fmt , __func__, ## __VA_ARGS__) -#else
> -#define DPRINTF(fmt, ...) do {} while (0) -#endif
> +#define DPRINTF(fmt, ...) G_STMT_START \
> +    if (DEBUG_UC32) { \
> +        printf("%s: " fmt , __func__, ## __VA_ARGS__); \
> +    } \
> +    G_STMT_END
> 
>  CPUUniCore32State *uc32_cpu_init(const char *cpu_model)  { diff --git
> a/target-unicore32/softmmu.c b/target-unicore32/softmmu.c index
> fc27100..2ce30d9 100644
> --- a/target-unicore32/softmmu.c
> +++ b/target-unicore32/softmmu.c
> @@ -14,13 +14,13 @@
> 
>  #include <cpu.h>
> 
> -#undef DEBUG_UC32
> +#define DEBUG_UC32 0
> 
> -#ifdef DEBUG_UC32
> -#define DPRINTF(fmt, ...) printf("%s: " fmt , __func__, ## __VA_ARGS__) -#else
> -#define DPRINTF(fmt, ...) do {} while (0) -#endif
> +#define DPRINTF(fmt, ...) G_STMT_START \
> +    if (DEBUG_UC32) { \
> +        printf("%s: " fmt , __func__, ## __VA_ARGS__); \
> +    } \
> +    G_STMT_END
> 
>  #define SUPERPAGE_SIZE             (1 << 22)
>  #define UC32_PAGETABLE_READ        (1 << 8)
> --
> 1.7.10.4
Andreas Färber Jan. 29, 2013, 10:51 a.m. UTC | #2
Am 29.01.2013 10:23, schrieb Guan Xuetao:
>> -----邮件原件-----
>> 发件人: Andreas Färber [mailto:afaerber@suse.de]
>> 发送时间: Sunday, January 27, 2013 21:32
>> 收件人: qemu-devel@nongnu.org
>> 抄送: Andreas Färber; Guan Xuetao (maintainer:UniCore32)
>> 主题: [RFC 19/19] target-unicore32: Refactor debug output macros
>>
>> Make debug output compile-testable even if disabled.
>>
>> Signed-off-by: Andreas Färber <afaerber@suse.de>
> 
> The patch could work, but I don't think it's a good idea.

Yes, I agree. The plan for v2 is to use static inline functions and to
keep using #ifdef rather than #if.

> Perhaps tracetools can be better.

Tracepoints are not as flexible as they require a fixed set of up to
6(?) arguments. But yes, if you were to replace these macros in
unicore32 code with specific tracepoints that would solve the issue at
hand as well and would even allow to enable/disable them at runtime.

CC'ing some more people on this new input. Maybe there would be a common
subset of tracepoints? Anthony mentioned LOG_EXCP and LOG_DIS; would not
only the names but also the arguments be generalizable?

Regards,
Andreas
diff mbox

Patch

diff --git a/target-unicore32/helper.c b/target-unicore32/helper.c
index 5359538..688c985 100644
--- a/target-unicore32/helper.c
+++ b/target-unicore32/helper.c
@@ -17,13 +17,13 @@ 
 #include "ui/console.h"
 #endif
 
-#undef DEBUG_UC32
+#define DEBUG_UC32 0
 
-#ifdef DEBUG_UC32
-#define DPRINTF(fmt, ...) printf("%s: " fmt , __func__, ## __VA_ARGS__)
-#else
-#define DPRINTF(fmt, ...) do {} while (0)
-#endif
+#define DPRINTF(fmt, ...) G_STMT_START \
+    if (DEBUG_UC32) { \
+        printf("%s: " fmt , __func__, ## __VA_ARGS__); \
+    } \
+    G_STMT_END
 
 CPUUniCore32State *uc32_cpu_init(const char *cpu_model)
 {
diff --git a/target-unicore32/softmmu.c b/target-unicore32/softmmu.c
index fc27100..2ce30d9 100644
--- a/target-unicore32/softmmu.c
+++ b/target-unicore32/softmmu.c
@@ -14,13 +14,13 @@ 
 
 #include <cpu.h>
 
-#undef DEBUG_UC32
+#define DEBUG_UC32 0
 
-#ifdef DEBUG_UC32
-#define DPRINTF(fmt, ...) printf("%s: " fmt , __func__, ## __VA_ARGS__)
-#else
-#define DPRINTF(fmt, ...) do {} while (0)
-#endif
+#define DPRINTF(fmt, ...) G_STMT_START \
+    if (DEBUG_UC32) { \
+        printf("%s: " fmt , __func__, ## __VA_ARGS__); \
+    } \
+    G_STMT_END
 
 #define SUPERPAGE_SIZE             (1 << 22)
 #define UC32_PAGETABLE_READ        (1 << 8)