[RFC 12/19] target-i386: Refactor debug output macros

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

 



Make debug output compile-testable even if disabled.

Signed-off-by: Andreas Färber <afaerber@xxxxxxx>
Cc: Richard Henderson <rth@xxxxxxxxxxx>
---
 target-i386/helper.c     |   33 ++++++++++++++++-----------------
 target-i386/kvm.c        |   16 +++++++---------
 target-i386/seg_helper.c |   20 +++++++++++---------
 3 Dateien geändert, 34 Zeilen hinzugefügt(+), 35 Zeilen entfernt(-)

diff --git a/target-i386/helper.c b/target-i386/helper.c
index 547c25e..aa94289 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -24,7 +24,12 @@
 #include "monitor/monitor.h"
 #endif
 
-//#define DEBUG_MMU
+#define DEBUG_MMU 0
+#define MMU_DPRINTF(...) G_STMT_START \
+    if (DEBUG_MMU) { \
+        printf(__VA_ARGS__); \
+    } \
+    G_STMT_END
 
 static void cpu_x86_version(CPUX86State *env, int *family, int *model)
 {
@@ -370,9 +375,8 @@ void cpu_x86_set_a20(CPUX86State *env, int a20_state)
 {
     a20_state = (a20_state != 0);
     if (a20_state != ((env->a20_mask >> 20) & 1)) {
-#if defined(DEBUG_MMU)
-        printf("A20 update: a20=%d\n", a20_state);
-#endif
+        MMU_DPRINTF("A20 update: a20=%d\n", a20_state);
+
         /* if the cpu is currently executing code, we must unlink it and
            all the potentially executing TB */
         cpu_interrupt(env, CPU_INTERRUPT_EXITTB);
@@ -388,9 +392,8 @@ void cpu_x86_update_cr0(CPUX86State *env, uint32_t new_cr0)
 {
     int pe_state;
 
-#if defined(DEBUG_MMU)
-    printf("CR0 update: CR0=0x%08x\n", new_cr0);
-#endif
+    MMU_DPRINTF("CR0 update: CR0=0x%08x\n", new_cr0);
+
     if ((new_cr0 & (CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK)) !=
         (env->cr[0] & (CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK))) {
         tlb_flush(env, 1);
@@ -431,18 +434,15 @@ void cpu_x86_update_cr3(CPUX86State *env, target_ulong new_cr3)
 {
     env->cr[3] = new_cr3;
     if (env->cr[0] & CR0_PG_MASK) {
-#if defined(DEBUG_MMU)
-        printf("CR3 update: CR3=" TARGET_FMT_lx "\n", new_cr3);
-#endif
+        MMU_DPRINTF("CR3 update: CR3=" TARGET_FMT_lx "\n", new_cr3);
         tlb_flush(env, 0);
     }
 }
 
 void cpu_x86_update_cr4(CPUX86State *env, uint32_t new_cr4)
 {
-#if defined(DEBUG_MMU)
-    printf("CR4 update: CR4=%08x\n", (uint32_t)env->cr[4]);
-#endif
+    MMU_DPRINTF("CR4 update: CR4=%08x\n", (uint32_t)env->cr[4]);
+
     if ((new_cr4 ^ env->cr[4]) &
         (CR4_PGE_MASK | CR4_PAE_MASK | CR4_PSE_MASK |
          CR4_SMEP_MASK | CR4_SMAP_MASK)) {
@@ -508,10 +508,9 @@ int cpu_x86_handle_mmu_fault(CPUX86State *env, target_ulong addr,
     target_ulong vaddr, virt_addr;
 
     is_user = mmu_idx == MMU_USER_IDX;
-#if defined(DEBUG_MMU)
-    printf("MMU fault: addr=" TARGET_FMT_lx " w=%d u=%d eip=" TARGET_FMT_lx "\n",
-           addr, is_write1, is_user, env->eip);
-#endif
+    MMU_DPRINTF("MMU fault: addr=" TARGET_FMT_lx " w=%d u=%d"
+                " eip=" TARGET_FMT_lx "\n",
+                addr, is_write1, is_user, env->eip);
     is_write = is_write1 & 1;
 
     if (!(env->cr[0] & CR0_PG_MASK)) {
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 3acff40..732e5fd 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -34,15 +34,13 @@
 #include "hyperv.h"
 #include "hw/pci/pci.h"
 
-//#define DEBUG_KVM
-
-#ifdef DEBUG_KVM
-#define DPRINTF(fmt, ...) \
-    do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
-#else
-#define DPRINTF(fmt, ...) \
-    do { } while (0)
-#endif
+#define DEBUG_KVM 0
+
+#define DPRINTF(fmt, ...) G_STMT_START \
+    if (DEBUG_KVM) { \
+        fprintf(stderr, fmt, ## __VA_ARGS__); \
+    } \
+    G_STMT_END
 
 #define MSR_KVM_WALL_CLOCK  0x11
 #define MSR_KVM_SYSTEM_TIME 0x12
diff --git a/target-i386/seg_helper.c b/target-i386/seg_helper.c
index 3247dee..b626b68 100644
--- a/target-i386/seg_helper.c
+++ b/target-i386/seg_helper.c
@@ -22,20 +22,22 @@
 #include "qemu/log.h"
 #include "helper.h"
 
-//#define DEBUG_PCALL
+#define DEBUG_PCALL 0
 
 #if !defined(CONFIG_USER_ONLY)
 #include "exec/softmmu_exec.h"
 #endif /* !defined(CONFIG_USER_ONLY) */
 
-#ifdef DEBUG_PCALL
-# define LOG_PCALL(...) qemu_log_mask(CPU_LOG_PCALL, ## __VA_ARGS__)
-# define LOG_PCALL_STATE(env)                                  \
-    log_cpu_state_mask(CPU_LOG_PCALL, (env), CPU_DUMP_CCOP)
-#else
-# define LOG_PCALL(...) do { } while (0)
-# define LOG_PCALL_STATE(env) do { } while (0)
-#endif
+#define LOG_PCALL(...) G_STMT_START \
+    if (DEBUG_PCALL) { \
+        qemu_log_mask(CPU_LOG_PCALL, ## __VA_ARGS__); \
+    } \
+    G_STMT_END
+#define LOG_PCALL_STATE(env) G_STMT_START \
+    if (DEBUG_PCALL) { \
+        log_cpu_state_mask(CPU_LOG_PCALL, (env), CPU_DUMP_CCOP); \
+    } \
+    G_STMT_END
 
 /* return non zero if error */
 static inline int load_segment(CPUX86State *env, uint32_t *e1_ptr,
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux