Make debug output compile-testable even if disabled.

Introduce DPRINTF() in helper.c and consolidate stdout and stderr
output.
Introduce DPRINTF() in mmu.c and inline remaining D(x).
Drop unused D(x) macro in op_helper.c.

Signed-off-by: Andreas Färber <afaer...@suse.de>
---
 target-cris/helper.c    |   21 +++++++++--------
 target-cris/mmu.c       |   58 +++++++++++++++++++++++++++--------------------
 target-cris/op_helper.c |   15 +++++-------
 target-cris/translate.c |   18 ++++-----------
 4 Dateien geändert, 56 Zeilen hinzugefügt(+), 56 Zeilen entfernt(-)

diff --git a/target-cris/helper.c b/target-cris/helper.c
index de04143..31bf358 100644
--- a/target-cris/helper.c
+++ b/target-cris/helper.c
@@ -23,16 +23,17 @@
 #include "qemu/host-utils.h"
 
 
-//#define CRIS_HELPER_DEBUG
+#define CRIS_HELPER_DEBUG 0
 
+#define D_LOG(...) G_STMT_START \
+    if (CRIS_HELPER_DEBUG) { \
+        qemu_log(__VA_ARGS__); \
+    } G_STMT_END
 
-#ifdef CRIS_HELPER_DEBUG
-#define D(x) x
-#define D_LOG(...) qemu_log(__VA_ARGS__)
-#else
-#define D(x)
-#define D_LOG(...) do { } while (0)
-#endif
+#define DPRINTF(...) G_STMT_START \
+    if (CRIS_HELPER_DEBUG) { \
+        fprintf(stderr, ## __VA_ARGS__); \
+    } G_STMT_END
 
 #if defined(CONFIG_USER_ONLY)
 
@@ -71,7 +72,7 @@ int cpu_cris_handle_mmu_fault(CPUCRISState *env, target_ulong 
address, int rw,
     int r = -1;
     target_ulong phy;
 
-    D(printf("%s addr=%x pc=%x rw=%x\n", __func__, address, env->pc, rw));
+    DPRINTF("%s addr=%x pc=%x rw=%x\n", __func__, address, env->pc, rw);
     miss = cris_mmu_translate(&res, env, address & TARGET_PAGE_MASK,
                               rw, mmu_idx, 0);
     if (miss) {
@@ -259,7 +260,7 @@ hwaddr cpu_get_phys_page_debug(CPUCRISState * env, 
target_ulong addr)
     if (!miss) {
         phy = res.phy;
     }
-    D(fprintf(stderr, "%s %x -> %x\n", __func__, addr, phy));
+    DPRINTF("%s %x -> %x\n", __func__, addr, phy);
     return phy;
 }
 #endif
diff --git a/target-cris/mmu.c b/target-cris/mmu.c
index ee31e2a..f930230 100644
--- a/target-cris/mmu.c
+++ b/target-cris/mmu.c
@@ -24,13 +24,23 @@
 #include "mmu.h"
 
 #ifdef DEBUG
-#define D(x) x
-#define D_LOG(...) qemu_log(__VA_ARGS__)
+#define CRIS_ENABLE_DEBUG 1
 #else
-#define D(x) do { } while (0)
-#define D_LOG(...) do { } while (0)
+#define CRIS_ENABLE_DEBUG 0
 #endif
 
+#define DPRINTF(...) G_STMT_START \
+    if (CRIS_ENABLE_DEBUG) { \
+        printf(__VA_ARGS__); \
+    } \
+    G_STMT_END
+
+#define D_LOG(...) G_STMT_START \
+    if (CRIS_ENABLE_DEBUG) { \
+        qemu_log(__VA_ARGS__); \
+    } \
+    G_STMT_END
+
 void cris_mmu_init(CPUCRISState *env)
 {
        env->mmu_rand_lfsr = 0xcccc;
@@ -105,7 +115,6 @@ static inline void set_field(uint32_t *dst, unsigned int 
val,
        *dst |= val;
 }
 
-#ifdef DEBUG
 static void dump_tlb(CPUCRISState *env, int mmu)
 {
        int set;
@@ -124,7 +133,6 @@ static void dump_tlb(CPUCRISState *env, int mmu)
                }
        }
 }
-#endif
 
 /* rw 0 = read, 1 = write, 2 = exec.  */
 static int cris_mmu_translate_page(struct cris_mmu_result *res,
@@ -225,23 +233,23 @@ static int cris_mmu_translate_page(struct cris_mmu_result 
*res,
         set_exception_vector(0x0b, d_mmu_write);
         */
         if (cfg_k && tlb_k && usermode) {
-            D(printf("tlb: kernel protected %x lo=%x pc=%x\n",
-                     vaddr, lo, env->pc));
+            DPRINTF("tlb: kernel protected %x lo=%x pc=%x\n",
+                    vaddr, lo, env->pc);
             match = 0;
             res->bf_vec = vect_base + 2;
         } else if (rw == 1 && cfg_w && !tlb_w) {
-            D(printf("tlb: write protected %x lo=%x pc=%x\n",
-                     vaddr, lo, env->pc));
+            DPRINTF("tlb: write protected %x lo=%x pc=%x\n",
+                    vaddr, lo, env->pc);
             match = 0;
             /* write accesses never go through the I mmu.  */
             res->bf_vec = vect_base + 3;
         } else if (rw == 2 && cfg_x && !tlb_x) {
-            D(printf("tlb: exec protected %x lo=%x pc=%x\n",
-                     vaddr, lo, env->pc));
+            DPRINTF("tlb: exec protected %x lo=%x pc=%x\n",
+                    vaddr, lo, env->pc);
             match = 0;
             res->bf_vec = vect_base + 3;
         } else if (cfg_v && !tlb_v) {
-            D(printf("tlb: invalid %x\n", vaddr));
+            DPRINTF("tlb: invalid %x\n", vaddr);
             match = 0;
             res->bf_vec = vect_base + 1;
         }
@@ -256,7 +264,9 @@ static int cris_mmu_translate_page(struct cris_mmu_result 
*res,
                 res->prot |= PAGE_EXEC;
             }
         } else {
-            D(dump_tlb(env, mmu));
+            if (CRIS_ENABLE_DEBUG) {
+                dump_tlb(env, mmu);
+            }
         }
     } else {
         /* If refill, provide a randomized set.  */
@@ -279,18 +289,18 @@ static int cris_mmu_translate_page(struct cris_mmu_result 
*res,
         set_field(&r_cause, vpage, 13, 19);
         set_field(&r_cause, pid, 0, 8);
         env->sregs[SFR_R_MM_CAUSE] = r_cause;
-        D(printf("refill vaddr=%x pc=%x\n", vaddr, env->pc));
+        DPRINTF("refill vaddr=%x pc=%x\n", vaddr, env->pc);
     }
 
-    D(printf("%s rw=%d mtch=%d pc=%x va=%x vpn=%x tlbvpn=%x pfn=%x pid=%x"
-             " %x cause=%x sel=%x sp=%x %x %x\n",
-             __func__, rw, match, env->pc,
-             vaddr, vpage,
-             tlb_vpn, tlb_pfn, tlb_pid,
-             pid,
-             r_cause,
-             env->sregs[SFR_RW_MM_TLB_SEL],
-             env->regs[R_SP], env->pregs[PR_USP], env->ksp));
+    DPRINTF("%s rw=%d mtch=%d pc=%x va=%x vpn=%x tlbvpn=%x pfn=%x pid=%x"
+            " %x cause=%x sel=%x sp=%x %x %x\n",
+            __func__, rw, match, env->pc,
+            vaddr, vpage,
+            tlb_vpn, tlb_pfn, tlb_pid,
+            pid,
+            r_cause,
+            env->sregs[SFR_RW_MM_TLB_SEL],
+            env->regs[R_SP], env->pregs[PR_USP], env->ksp);
 
     res->phy = tlb_pfn << TARGET_PAGE_BITS;
     return !match;
diff --git a/target-cris/op_helper.c b/target-cris/op_helper.c
index b580513..da37f40 100644
--- a/target-cris/op_helper.c
+++ b/target-cris/op_helper.c
@@ -23,16 +23,13 @@
 #include "helper.h"
 #include "qemu/host-utils.h"
 
-//#define CRIS_OP_HELPER_DEBUG
+#define CRIS_OP_HELPER_DEBUG 0
 
-
-#ifdef CRIS_OP_HELPER_DEBUG
-#define D(x) x
-#define D_LOG(...) qemu_log(__VA_ARGS__)
-#else
-#define D(x)
-#define D_LOG(...) do { } while (0)
-#endif
+#define D_LOG(...) G_STMT_START \
+    if (CRIS_OP_HELPER_DEBUG) { \
+        qemu_log(__VA_ARGS__); \
+    } \
+    G_STMT_END
 
 #if !defined(CONFIG_USER_ONLY)
 #include "exec/softmmu_exec.h"
diff --git a/target-cris/translate.c b/target-cris/translate.c
index 09e6011..88ad038 100644
--- a/target-cris/translate.c
+++ b/target-cris/translate.c
@@ -34,11 +34,11 @@
 #include "helper.h"
 
 #define DISAS_CRIS 0
-#if DISAS_CRIS
-#  define LOG_DIS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
-#else
-#  define LOG_DIS(...) do { } while (0)
-#endif
+#define LOG_DIS(...) G_STMT_START \
+    if (DISAS_CRIS) { \
+        qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__); \
+    } \
+    G_STMT_END
 
 #define D(x)
 #define BUG() (gen_BUG(dc, __FILE__, __LINE__))
@@ -1263,7 +1263,6 @@ static inline void t_gen_zext(TCGv d, TCGv s, int size)
     }
 }
 
-#if DISAS_CRIS
 static char memsize_char(int size)
 {
     switch (size) {
@@ -1275,7 +1274,6 @@ static char memsize_char(int size)
         break;
     }
 }
-#endif
 
 static inline unsigned int memsize_z(DisasContext *dc)
 {
@@ -1370,7 +1368,6 @@ static int dec_prep_alu_m(CPUCRISState *env, DisasContext 
*dc,
     return insn_len;
 }
 
-#if DISAS_CRIS
 static const char *cc_name(int cc)
 {
     static const char *cc_names[16] = {
@@ -1380,7 +1377,6 @@ static const char *cc_name(int cc)
     assert(cc < 16);
     return cc_names[cc];
 }
-#endif
 
 /* Start of insn decoders.  */
 
@@ -1842,7 +1838,6 @@ static int dec_mcp_r(CPUCRISState *env, DisasContext *dc)
     return 2;
 }
 
-#if DISAS_CRIS
 static char * swapmode_name(int mode, char *modename) {
     int i = 0;
     if (mode & 8) {
@@ -1860,14 +1855,11 @@ static char * swapmode_name(int mode, char *modename) {
     modename[i++] = 0;
     return modename;
 }
-#endif
 
 static int dec_swap_r(CPUCRISState *env, DisasContext *dc)
 {
     TCGv t0;
-#if DISAS_CRIS
     char modename[4];
-#endif
     LOG_DIS("swap%s $r%u\n",
              swapmode_name(dc->op2, modename), dc->op1);
 
-- 
1.7.10.4


Reply via email to