qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 36/43] gpi: made printf always compile in debug outp


From: Danil Antonov
Subject: [Qemu-devel] [PATCH 36/43] gpi: made printf always compile in debug output
Date: Sat, 1 Apr 2017 17:06:28 +0300

>From adb8f4b937b80629881ea23310a8d75ac4671b2a Mon Sep 17 00:00:00 2001
From: Danil Antonov <address@hidden>
Date: Wed, 29 Mar 2017 12:41:38 +0300
Subject: [PATCH 36/43] gpi: 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/gpio/pl061.c     | 28 ++++++++++++++++------------
 hw/gpio/puv3_gpio.c |  8 ++++----
 2 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/hw/gpio/pl061.c b/hw/gpio/pl061.c
index 4ae2aa1..af0de24 100644
--- a/hw/gpio/pl061.c
+++ b/hw/gpio/pl061.c
@@ -12,18 +12,22 @@
 #include "hw/sysbus.h"
 #include "qemu/log.h"

-//#define DEBUG_PL061 1
-
-#ifdef DEBUG_PL061
-#define DPRINTF(fmt, ...) \
-do { printf("pl061: " fmt , ## __VA_ARGS__); } while (0)
-#define BADF(fmt, ...) \
-do { fprintf(stderr, "pl061: error: " fmt , ## __VA_ARGS__); exit(1);}
while (0)
-#else
-#define DPRINTF(fmt, ...) do {} while(0)
-#define BADF(fmt, ...) \
-do { fprintf(stderr, "pl061: error: " fmt , ## __VA_ARGS__);} while (0)
-#endif
+#ifndef DEBUG_PL061
+#define DEBUG_PL061  0
+#endif
+
+#define DPRINTF(fmt, ...) do {                           \
+    if (DEBUG_PL061) {                                   \
+        fprintf(stderr, "pl061: " fmt , ## __VA_ARGS__); \
+    }                                                    \
+} while (0);
+
+#define BADF(fmt, ...) do {                                 \
+    fprintf(stderr, "pl061: error: " fmt , ## __VA_ARGS__); \
+    if (DEBUG_PL061) {                                      \
+        exit(1);                                            \
+    }                                                       \
+} while (0);

 static const uint8_t pl061_id[12] =
   { 0x00, 0x00, 0x00, 0x00, 0x61, 0x10, 0x04, 0x00, 0x0d, 0xf0, 0x05, 0xb1
};
diff --git a/hw/gpio/puv3_gpio.c b/hw/gpio/puv3_gpio.c
index 445afcc..48a8a4b 100644
--- a/hw/gpio/puv3_gpio.c
+++ b/hw/gpio/puv3_gpio.c
@@ -46,9 +46,9 @@ static uint64_t puv3_gpio_read(void *opaque, hwaddr
offset,
         ret = s->reg_GPIR;
         break;
     default:
-        DPRINTF("Bad offset 0x%x\n", offset);
+        DPRINTF("Bad offset 0x%lx\n", offset);
     }
-    DPRINTF("offset 0x%x, value 0x%x\n", offset, ret);
+    DPRINTF("offset 0x%lx, value 0x%x\n", offset, ret);

     return ret;
 }
@@ -58,7 +58,7 @@ static void puv3_gpio_write(void *opaque, hwaddr offset,
 {
     PUV3GPIOState *s = opaque;

-    DPRINTF("offset 0x%x, value 0x%x\n", offset, value);
+    DPRINTF("offset 0x%lx, value 0x%lx\n", offset, value);
     switch (offset) {
     case 0x04:
         s->reg_GPDR = value;
@@ -85,7 +85,7 @@ static void puv3_gpio_write(void *opaque, hwaddr offset,
         s->reg_GPIR = value;
         break;
     default:
-        DPRINTF("Bad offset 0x%x\n", offset);
+        DPRINTF("Bad offset 0x%lx\n", offset);
     }
 }

-- 
2.8.0.rc3


reply via email to

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