Patchwork [v2,15/15] target-unicore32: Refactor debug output macros

login
register
mail settings
Submitter Andreas Färber
Date Feb. 21, 2013, 4:25 a.m.
Message ID <1361420711-15698-16-git-send-email-afaerber@suse.de>
Download mbox | patch
Permalink /patch/222175/
State New
Headers show

Comments

Andreas Färber - Feb. 21, 2013, 4:25 a.m.
Make debug output compile-testable even if disabled.

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

Patch

diff --git a/target-unicore32/helper.c b/target-unicore32/helper.c
index 7eeb9bc..d462ced 100644
--- a/target-unicore32/helper.c
+++ b/target-unicore32/helper.c
@@ -20,9 +20,23 @@ 
 #undef DEBUG_UC32
 
 #ifdef DEBUG_UC32
-#define DPRINTF(fmt, ...) printf("%s: " fmt , __func__, ## __VA_ARGS__)
+static const bool debug_helper = true;
 #else
-#define DPRINTF(fmt, ...) do {} while (0)
+static const bool debug_helper;
+#endif
+
+#define DPRINTF(fmt, ...) \
+    helper_dprintf("%s: " fmt , __func__, ## __VA_ARGS__)
+#ifndef CONFIG_USER_ONLY
+static void GCC_FMT_ATTR(1, 2) helper_dprintf(const char *fmt, ...)
+{
+    if (debug_helper) {
+        va_list ap;
+        va_start(ap, fmt);
+        vprintf(fmt, ap);
+        va_end(ap);
+    }
+}
 #endif
 
 CPUUniCore32State *uc32_cpu_init(const char *cpu_model)
diff --git a/target-unicore32/softmmu.c b/target-unicore32/softmmu.c
index fc27100..d45fafc 100644
--- a/target-unicore32/softmmu.c
+++ b/target-unicore32/softmmu.c
@@ -17,11 +17,24 @@ 
 #undef DEBUG_UC32
 
 #ifdef DEBUG_UC32
-#define DPRINTF(fmt, ...) printf("%s: " fmt , __func__, ## __VA_ARGS__)
+static const bool debug_softmmu = true;
 #else
-#define DPRINTF(fmt, ...) do {} while (0)
+static const bool debug_softmmu;
 #endif
 
+#define DPRINTF(fmt, ...) \
+    softmmu_dprintf("%s: " fmt , __func__, ## __VA_ARGS__)
+
+static void GCC_FMT_ATTR(1, 2) softmmu_dprintf(const char *fmt, ...)
+{
+    if (debug_softmmu) {
+        va_list ap;
+        va_start(ap, fmt);
+        vprintf(fmt, ap);
+        va_end(ap);
+    }
+}
+
 #define SUPERPAGE_SIZE             (1 << 22)
 #define UC32_PAGETABLE_READ        (1 << 8)
 #define UC32_PAGETABLE_WRITE       (1 << 7)