qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 20/43] i386: made printf always compile in debug out


From: Danil Antonov
Subject: [Qemu-devel] [PATCH 20/43] i386: made printf always compile in debug output
Date: Sat, 1 Apr 2017 16:55:36 +0300

>From a132733828991a950855138982d4a60858e92b04 Mon Sep 17 00:00:00 2001
From: Danil Antonov <address@hidden>
Date: Wed, 29 Mar 2017 12:32:16 +0300
Subject: [PATCH 20/43] i386: made printf always compile in debug output

Wrapped printf calls inside debug macros (DPRINTF) in `if` statement.
This will ensure that printf function will always compile even if debug
output is turned off and, in turn, will prevent bitrot of the format
strings.

Signed-off-by: Danil Antonov <address@hidden>
---
 hw/i386/acpi-build.c       | 17 +++++++++++------
 hw/i386/intel_iommu.c      | 18 +++++++++---------
 hw/i386/pc.c               | 16 ++++++++++------
 hw/i386/xen/xen_platform.c | 17 ++++++++++-------
 4 files changed, 40 insertions(+), 28 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 2073108..53b3aaf 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -75,12 +75,17 @@
 #define ACPI_BUILD_TABLE_SIZE             0x20000

 /* #define DEBUG_ACPI_BUILD */
-#ifdef DEBUG_ACPI_BUILD
-#define ACPI_BUILD_DPRINTF(fmt, ...)        \
-    do {printf("ACPI_BUILD: " fmt, ## __VA_ARGS__); } while (0)
-#else
-#define ACPI_BUILD_DPRINTF(fmt, ...)
-#endif
+
+#ifndef DEBUG_ACPI_BUILD
+#define DEBUG_ACPI_BUILD 0
+#endif
+
+#define ACPI_BUILD_DPRINTF(fmt, ...)                             \
+    do {                                                         \
+        if (DEBUG_ACPI_BUILD) {                                  \
+            fprintf(stderr, "ACPI_BUILD: " fmt, ## __VA_ARGS__); \
+        }                                                        \
+    } while (0)

 /* Default IOAPIC ID */
 #define ACPI_BUILD_IOAPIC_ID 0x0
diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 22d8226..562588b 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -37,8 +37,10 @@
 #include "kvm_i386.h"
 #include "trace.h"

-/*#define DEBUG_INTEL_IOMMU*/
-#ifdef DEBUG_INTEL_IOMMU
+#ifndef DEBUG_INTEL_IOMMU
+#define DEBUG_INTEL_IOMMU 0
+#endif
+
 enum {
     DEBUG_GENERAL, DEBUG_CSR, DEBUG_INV, DEBUG_MMU, DEBUG_FLOG,
     DEBUG_CACHE, DEBUG_IR,
@@ -46,14 +48,12 @@ enum {
 #define VTD_DBGBIT(x)   (1 << DEBUG_##x)
 static int vtd_dbgflags = VTD_DBGBIT(GENERAL) | VTD_DBGBIT(CSR);

-#define VTD_DPRINTF(what, fmt, ...) do { \
-    if (vtd_dbgflags & VTD_DBGBIT(what)) { \
-        fprintf(stderr, "(vtd)%s: " fmt "\n", __func__, \
-                ## __VA_ARGS__); } \
+#define VTD_DPRINTF(what, fmt,
...)                                                  \
+    do
{                                                                       \
+        if (DEBUG_INTEL_IOMMU && vtd_dbgflags & VTD_DBGBIT(what))
{            \
+            fprintf(stderr, "(vtd)%s: " fmt "\n", __func__, ##
__VA_ARGS__);   \
+
}                                                                      \
     } while (0)
-#else
-#define VTD_DPRINTF(what, fmt, ...) do {} while (0)
-#endif

 static void vtd_define_quad(IntelIOMMUState *s, hwaddr addr, uint64_t val,
                             uint64_t wmask, uint64_t w1cmask)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index d24388e..87b4312 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -73,12 +73,16 @@
 /* debug PC/ISA interrupts */
 //#define DEBUG_IRQ

-#ifdef DEBUG_IRQ
-#define DPRINTF(fmt, ...)                                       \
-    do { printf("CPUIRQ: " fmt , ## __VA_ARGS__); } while (0)
-#else
-#define DPRINTF(fmt, ...)
-#endif
+#ifndef DEBUG_IRQ
+#define DEBUG_IRQ 0
+#endif
+
+#define DPRINTF(fmt, ...)                                    \
+    do {                                                     \
+        if (DEBUG_IRQ) {                                     \
+            fprintf(stderr, "CPUIRQ: " fmt, ## __VA_ARGS__); \
+        }                                                    \
+    } while (0)

 #define FW_CFG_ACPI_TABLES (FW_CFG_ARCH_LOCAL + 0)
 #define FW_CFG_SMBIOS_ENTRIES (FW_CFG_ARCH_LOCAL + 1)
diff --git a/hw/i386/xen/xen_platform.c b/hw/i386/xen/xen_platform.c
index 6010f35..218bc2f 100644
--- a/hw/i386/xen/xen_platform.c
+++ b/hw/i386/xen/xen_platform.c
@@ -41,13 +41,16 @@

 //#define DEBUG_PLATFORM

-#ifdef DEBUG_PLATFORM
-#define DPRINTF(fmt, ...) do { \
-    fprintf(stderr, "xen_platform: " fmt, ## __VA_ARGS__); \
-} while (0)
-#else
-#define DPRINTF(fmt, ...) do { } while (0)
-#endif
+#ifndef DEBUG_PLATFORM
+#define DEBUG_PLATFORM 0
+#endif
+
+#define DPRINTF(fmt, ...)                                          \
+    do {                                                           \
+        if (DEBUG_PLATFORM) {                                      \
+            fprintf(stderr, "xen_platform: " fmt, ## __VA_ARGS__); \
+        }                                                          \
+    } while (0)

 #define PFFLAG_ROM_LOCK 1 /* Sets whether ROM memory area is RW or RO */

-- 
2.8.0.rc3


reply via email to

[Prev in Thread] Current Thread [Next in Thread]