All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2 0/6] Log unimplemented functionality
@ 2012-06-09 12:12 Blue Swirl
  2012-06-09 12:12 ` [Qemu-devel] [PATCH 1/6] qemu-log: move logging to qemu-log.c Blue Swirl
                   ` (6 more replies)
  0 siblings, 7 replies; 14+ messages in thread
From: Blue Swirl @ 2012-06-09 12:12 UTC (permalink / raw)
  To: qemu-devel

v2: address Kevin's comments to 5/6

Blue Swirl (6):
  qemu-log: move logging to qemu-log.c
  qemu-log: cleanup
  qemu-log: add log category for unimplemented functionality
  qemu-log: use LOG_UNIMP for some target CPU cases
  fdc: use LOG_UNIMP logging
  qtest: add a fuzz test to fdc-test

 Makefile.objs                 |    1 +
 cpu-all.h                     |   24 ------
 exec.c                        |  122 -----------------------------
 hw/fdc.c                      |   30 ++++---
 linux-user/main.c             |    3 +-
 linux-user/signal.c           |   12 +--
 qemu-log.c                    |  170 +++++++++++++++++++++++++++++++++++++++++
 qemu-log.h                    |  145 ++++++++++++++++++++++++-----------
 qemu-tool.c                   |    2 -
 target-i386/op_helper.c       |    1 +
 target-microblaze/translate.c |   11 ++-
 target-ppc/helper.c           |    2 +-
 target-s390x/translate.c      |    2 +-
 target-sparc/ldst_helper.c    |   80 ++++++++++++--------
 tcg/tcg.c                     |   92 ++++++++++++----------
 tcg/tcg.h                     |    2 +-
 tcg/tci/tcg-target.c          |    2 +-
 tests/fdc-test.c              |   17 ++++
 18 files changed, 419 insertions(+), 299 deletions(-)
 create mode 100644 qemu-log.c

-- 
1.7.2.5

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Qemu-devel] [PATCH 1/6] qemu-log: move logging to qemu-log.c
  2012-06-09 12:12 [Qemu-devel] [PATCH v2 0/6] Log unimplemented functionality Blue Swirl
@ 2012-06-09 12:12 ` Blue Swirl
  2012-07-03 10:07   ` Kevin Wolf
  2012-06-09 12:12 ` [Qemu-devel] [PATCH 2/6] qemu-log: cleanup Blue Swirl
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 14+ messages in thread
From: Blue Swirl @ 2012-06-09 12:12 UTC (permalink / raw)
  To: qemu-devel

Move logging functions from exec.c to qemu-log.c,
compile it only once.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
 Makefile.objs |    1 +
 cpu-all.h     |   24 ---------
 exec.c        |  122 -----------------------------------------------
 qemu-log.c    |  146 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 qemu-log.h    |   28 +++++++++--
 5 files changed, 170 insertions(+), 151 deletions(-)
 create mode 100644 qemu-log.c

diff --git a/Makefile.objs b/Makefile.objs
index 8e72f09..27d57bf 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -1,6 +1,7 @@
 #######################################################################
 # Target-independent parts used in system and user emulation
 universal-obj-y =
+universal-obj-y += qemu-log.o
 
 #######################################################################
 # QObject
diff --git a/cpu-all.h b/cpu-all.h
index 3a93c0c..50c8b62 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -446,30 +446,6 @@ void cpu_single_step(CPUArchState *env, int enabled);
 int cpu_is_stopped(CPUArchState *env);
 void run_on_cpu(CPUArchState *env, void (*func)(void *data), void *data);
 
-#define CPU_LOG_TB_OUT_ASM (1 << 0)
-#define CPU_LOG_TB_IN_ASM  (1 << 1)
-#define CPU_LOG_TB_OP      (1 << 2)
-#define CPU_LOG_TB_OP_OPT  (1 << 3)
-#define CPU_LOG_INT        (1 << 4)
-#define CPU_LOG_EXEC       (1 << 5)
-#define CPU_LOG_PCALL      (1 << 6)
-#define CPU_LOG_IOPORT     (1 << 7)
-#define CPU_LOG_TB_CPU     (1 << 8)
-#define CPU_LOG_RESET      (1 << 9)
-
-/* define log items */
-typedef struct CPULogItem {
-    int mask;
-    const char *name;
-    const char *help;
-} CPULogItem;
-
-extern const CPULogItem cpu_log_items[];
-
-void cpu_set_log(int log_flags);
-void cpu_set_log_filename(const char *filename);
-int cpu_str_to_log_mask(const char *str);
-
 #if !defined(CONFIG_USER_ONLY)
 
 /* Return the physical page corresponding to a virtual one. Use it
diff --git a/exec.c b/exec.c
index a587e7a..4a061cf 100644
--- a/exec.c
+++ b/exec.c
@@ -216,16 +216,6 @@ static void memory_map_init(void);
 static MemoryRegion io_mem_watch;
 #endif
 
-/* log support */
-#ifdef WIN32
-static const char *logfilename = "qemu.log";
-#else
-static const char *logfilename = "/tmp/qemu.log";
-#endif
-FILE *logfile;
-int loglevel;
-static int log_append = 0;
-
 /* statistics */
 static int tb_flush_count;
 static int tb_phys_invalidate_count;
@@ -1671,46 +1661,6 @@ void cpu_single_step(CPUArchState *env, int enabled)
 #endif
 }
 
-/* enable or disable low levels log */
-void cpu_set_log(int log_flags)
-{
-    loglevel = log_flags;
-    if (loglevel && !logfile) {
-        logfile = fopen(logfilename, log_append ? "a" : "w");
-        if (!logfile) {
-            perror(logfilename);
-            _exit(1);
-        }
-#if !defined(CONFIG_SOFTMMU)
-        /* must avoid mmap() usage of glibc by setting a buffer "by hand" */
-        {
-            static char logfile_buf[4096];
-            setvbuf(logfile, logfile_buf, _IOLBF, sizeof(logfile_buf));
-        }
-#elif defined(_WIN32)
-        /* Win32 doesn't support line-buffering, so use unbuffered output. */
-        setvbuf(logfile, NULL, _IONBF, 0);
-#else
-        setvbuf(logfile, NULL, _IOLBF, 0);
-#endif
-        log_append = 1;
-    }
-    if (!loglevel && logfile) {
-        fclose(logfile);
-        logfile = NULL;
-    }
-}
-
-void cpu_set_log_filename(const char *filename)
-{
-    logfilename = strdup(filename);
-    if (logfile) {
-        fclose(logfile);
-        logfile = NULL;
-    }
-    cpu_set_log(loglevel);
-}
-
 static void cpu_unlink_tb(CPUArchState *env)
 {
     /* FIXME: TB unchaining isn't SMP safe.  For now just ignore the
@@ -1782,78 +1732,6 @@ void cpu_exit(CPUArchState *env)
     cpu_unlink_tb(env);
 }
 
-const CPULogItem cpu_log_items[] = {
-    { CPU_LOG_TB_OUT_ASM, "out_asm",
-      "show generated host assembly code for each compiled TB" },
-    { CPU_LOG_TB_IN_ASM, "in_asm",
-      "show target assembly code for each compiled TB" },
-    { CPU_LOG_TB_OP, "op",
-      "show micro ops for each compiled TB" },
-    { CPU_LOG_TB_OP_OPT, "op_opt",
-      "show micro ops "
-#ifdef TARGET_I386
-      "before eflags optimization and "
-#endif
-      "after liveness analysis" },
-    { CPU_LOG_INT, "int",
-      "show interrupts/exceptions in short format" },
-    { CPU_LOG_EXEC, "exec",
-      "show trace before each executed TB (lots of logs)" },
-    { CPU_LOG_TB_CPU, "cpu",
-      "show CPU state before block translation" },
-#ifdef TARGET_I386
-    { CPU_LOG_PCALL, "pcall",
-      "show protected mode far calls/returns/exceptions" },
-    { CPU_LOG_RESET, "cpu_reset",
-      "show CPU state before CPU resets" },
-#endif
-#ifdef DEBUG_IOPORT
-    { CPU_LOG_IOPORT, "ioport",
-      "show all i/o ports accesses" },
-#endif
-    { 0, NULL, NULL },
-};
-
-static int cmp1(const char *s1, int n, const char *s2)
-{
-    if (strlen(s2) != n)
-        return 0;
-    return memcmp(s1, s2, n) == 0;
-}
-
-/* takes a comma separated list of log masks. Return 0 if error. */
-int cpu_str_to_log_mask(const char *str)
-{
-    const CPULogItem *item;
-    int mask;
-    const char *p, *p1;
-
-    p = str;
-    mask = 0;
-    for(;;) {
-        p1 = strchr(p, ',');
-        if (!p1)
-            p1 = p + strlen(p);
-        if(cmp1(p,p1-p,"all")) {
-            for(item = cpu_log_items; item->mask != 0; item++) {
-                mask |= item->mask;
-            }
-        } else {
-            for(item = cpu_log_items; item->mask != 0; item++) {
-                if (cmp1(p, p1 - p, item->name))
-                    goto found;
-            }
-            return 0;
-        }
-    found:
-        mask |= item->mask;
-        if (*p1 != ',')
-            break;
-        p = p1 + 1;
-    }
-    return mask;
-}
-
 void cpu_abort(CPUArchState *env, const char *fmt, ...)
 {
     va_list ap;
diff --git a/qemu-log.c b/qemu-log.c
new file mode 100644
index 0000000..4d7499f
--- /dev/null
+++ b/qemu-log.c
@@ -0,0 +1,146 @@
+/*
+ * Logging support
+ *
+ *  Copyright (c) 2003 Fabrice Bellard
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "qemu-common.h"
+#include "qemu-log.h"
+
+#ifdef WIN32
+static const char *logfilename = "qemu.log";
+#else
+static const char *logfilename = "/tmp/qemu.log";
+#endif
+FILE *logfile;
+int loglevel;
+static int log_append = 0;
+
+/* enable or disable low levels log */
+void cpu_set_log(int log_flags)
+{
+    loglevel = log_flags;
+    if (loglevel && !logfile) {
+        logfile = fopen(logfilename, log_append ? "a" : "w");
+        if (!logfile) {
+            perror(logfilename);
+            _exit(1);
+        }
+#if !defined(CONFIG_SOFTMMU)
+        /* must avoid mmap() usage of glibc by setting a buffer "by hand" */
+        {
+            static char logfile_buf[4096];
+            setvbuf(logfile, logfile_buf, _IOLBF, sizeof(logfile_buf));
+        }
+#elif defined(_WIN32)
+        /* Win32 doesn't support line-buffering, so use unbuffered output. */
+        setvbuf(logfile, NULL, _IONBF, 0);
+#else
+        setvbuf(logfile, NULL, _IOLBF, 0);
+#endif
+        log_append = 1;
+    }
+    if (!loglevel && logfile) {
+        fclose(logfile);
+        logfile = NULL;
+    }
+}
+
+void cpu_set_log_filename(const char *filename)
+{
+    logfilename = strdup(filename);
+    if (logfile) {
+        fclose(logfile);
+        logfile = NULL;
+    }
+    cpu_set_log(loglevel);
+}
+
+const CPULogItem cpu_log_items[] = {
+    { CPU_LOG_TB_OUT_ASM, "out_asm",
+      "show generated host assembly code for each compiled TB" },
+    { CPU_LOG_TB_IN_ASM, "in_asm",
+      "show target assembly code for each compiled TB" },
+    { CPU_LOG_TB_OP, "op",
+      "show micro ops for each compiled TB" },
+    { CPU_LOG_TB_OP_OPT, "op_opt",
+      "show micro ops "
+#ifdef TARGET_I386
+      "before eflags optimization and "
+#endif
+      "after liveness analysis" },
+    { CPU_LOG_INT, "int",
+      "show interrupts/exceptions in short format" },
+    { CPU_LOG_EXEC, "exec",
+      "show trace before each executed TB (lots of logs)" },
+    { CPU_LOG_TB_CPU, "cpu",
+      "show CPU state before block translation" },
+#ifdef TARGET_I386
+    { CPU_LOG_PCALL, "pcall",
+      "show protected mode far calls/returns/exceptions" },
+    { CPU_LOG_RESET, "cpu_reset",
+      "show CPU state before CPU resets" },
+#endif
+#ifdef DEBUG_IOPORT
+    { CPU_LOG_IOPORT, "ioport",
+      "show all i/o ports accesses" },
+#endif
+    { 0, NULL, NULL },
+};
+
+static int cmp1(const char *s1, int n, const char *s2)
+{
+    if (strlen(s2) != n) {
+        return 0;
+    }
+    return memcmp(s1, s2, n) == 0;
+}
+
+/* takes a comma separated list of log masks. Return 0 if error. */
+int cpu_str_to_log_mask(const char *str)
+{
+    const CPULogItem *item;
+    int mask;
+    const char *p, *p1;
+
+    p = str;
+    mask = 0;
+    for (;;) {
+        p1 = strchr(p, ',');
+        if (!p1) {
+            p1 = p + strlen(p);
+        }
+        if (cmp1(p,p1-p,"all")) {
+            for (item = cpu_log_items; item->mask != 0; item++) {
+                mask |= item->mask;
+            }
+        } else {
+            for (item = cpu_log_items; item->mask != 0; item++) {
+                if (cmp1(p, p1 - p, item->name)) {
+                    goto found;
+                }
+            }
+            return 0;
+        }
+    found:
+        mask |= item->mask;
+        if (*p1 != ',') {
+            break;
+        }
+        p = p1 + 1;
+    }
+    return mask;
+}
diff --git a/qemu-log.h b/qemu-log.h
index fccfb110..e04ee9a 100644
--- a/qemu-log.h
+++ b/qemu-log.h
@@ -5,7 +5,6 @@
 extern FILE *logfile;
 extern int loglevel;
 
-
 /* 
  * The new API:
  *
@@ -17,11 +16,21 @@ extern int loglevel;
  */
 #define qemu_log_enabled() (logfile != NULL)
 
+#define CPU_LOG_TB_OUT_ASM (1 << 0)
+#define CPU_LOG_TB_IN_ASM  (1 << 1)
+#define CPU_LOG_TB_OP      (1 << 2)
+#define CPU_LOG_TB_OP_OPT  (1 << 3)
+#define CPU_LOG_INT        (1 << 4)
+#define CPU_LOG_EXEC       (1 << 5)
+#define CPU_LOG_PCALL      (1 << 6)
+#define CPU_LOG_IOPORT     (1 << 7)
+#define CPU_LOG_TB_CPU     (1 << 8)
+#define CPU_LOG_RESET      (1 << 9)
+
 /* Returns true if a bit is set in the current loglevel mask
  */
 #define qemu_loglevel_mask(b) ((loglevel & (b)) != 0)
 
-
 /* Logging functions: */
 
 /* main logging function
@@ -46,8 +55,6 @@ extern int loglevel;
     } while (0)
 
 
-
-
 /* Special cases: */
 
 /* cpu_dump_state() logging functions: */
@@ -66,7 +73,6 @@ extern int loglevel;
 #define log_page_dump() page_dump(logfile)
 
 
-
 /* Maintenance: */
 
 /* fflush() the log file */
@@ -89,5 +95,17 @@ extern int loglevel;
             logfile = (f);            \
     } while (0)
 
+/* define log items */
+typedef struct CPULogItem {
+    int mask;
+    const char *name;
+    const char *help;
+} CPULogItem;
+
+extern const CPULogItem cpu_log_items[];
+
+void cpu_set_log(int log_flags);
+void cpu_set_log_filename(const char *filename);
+int cpu_str_to_log_mask(const char *str);
 
 #endif
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [Qemu-devel] [PATCH 2/6] qemu-log: cleanup
  2012-06-09 12:12 [Qemu-devel] [PATCH v2 0/6] Log unimplemented functionality Blue Swirl
  2012-06-09 12:12 ` [Qemu-devel] [PATCH 1/6] qemu-log: move logging to qemu-log.c Blue Swirl
@ 2012-06-09 12:12 ` Blue Swirl
  2012-06-09 12:12 ` [Qemu-devel] [PATCH 3/6] qemu-log: add log category for unimplemented functionality Blue Swirl
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 14+ messages in thread
From: Blue Swirl @ 2012-06-09 12:12 UTC (permalink / raw)
  To: qemu-devel

Don't use global variables directly but via accessor functions. Rename globals.

Convert macros to functions, add GCC format attributes.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
 linux-user/main.c    |    3 +-
 linux-user/signal.c  |   12 ++---
 qemu-log.c           |   54 ++++++++++++++++-------
 qemu-log.h           |  116 ++++++++++++++++++++++++++++++++------------------
 qemu-tool.c          |    2 -
 tcg/tcg.c            |   92 +++++++++++++++++++++------------------
 tcg/tcg.h            |    2 +-
 tcg/tci/tcg-target.c |    2 +-
 8 files changed, 170 insertions(+), 113 deletions(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index 49108b8..d0e0e4f 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -1306,8 +1306,9 @@ do {                                                                    \
     fprintf(stderr, fmt , ## __VA_ARGS__);                              \
     cpu_dump_state(env, stderr, fprintf, 0);                            \
     qemu_log(fmt, ## __VA_ARGS__);                                      \
-    if (logfile)                                                        \
+    if (qemu_log_enabled()) {                                           \
         log_cpu_state(env, 0);                                          \
+    }                                                                   \
 } while (0)
 
 static int do_store_exclusive(CPUPPCState *env)
diff --git a/linux-user/signal.c b/linux-user/signal.c
index b1e139d..43346dc 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -4378,8 +4378,7 @@ static void setup_frame(int sig, struct target_sigaction *ka,
 
 sigsegv:
     unlock_user_struct(frame, frame_addr, 1);
-    if (logfile)
-        fprintf (logfile, "segfaulting from setup_frame\n");
+    qemu_log("segfaulting from setup_frame\n");
     force_sig(TARGET_SIGSEGV);
 }
 
@@ -4447,8 +4446,7 @@ static void setup_rt_frame(int sig, struct target_sigaction *ka,
 
 sigsegv:
     unlock_user_struct(rt_sf, rt_sf_addr, 1);
-    if (logfile)
-        fprintf (logfile, "segfaulting from setup_rt_frame\n");
+    qemu_log("segfaulting from setup_rt_frame\n");
     force_sig(TARGET_SIGSEGV);
 
 }
@@ -4489,8 +4487,7 @@ long do_sigreturn(CPUPPCState *env)
 sigsegv:
     unlock_user_struct(sr, sr_addr, 1);
     unlock_user_struct(sc, sc_addr, 1);
-    if (logfile)
-        fprintf (logfile, "segfaulting from do_sigreturn\n");
+    qemu_log("segfaulting from do_sigreturn\n");
     force_sig(TARGET_SIGSEGV);
     return 0;
 }
@@ -4552,8 +4549,7 @@ long do_rt_sigreturn(CPUPPCState *env)
 
 sigsegv:
     unlock_user_struct(rt_sf, rt_sf_addr, 1);
-    if (logfile)
-        fprintf (logfile, "segfaulting from do_rt_sigreturn\n");
+    qemu_log("segfaulting from do_rt_sigreturn\n");
     force_sig(TARGET_SIGSEGV);
     return 0;
 }
diff --git a/qemu-log.c b/qemu-log.c
index 4d7499f..1dd3de4 100644
--- a/qemu-log.c
+++ b/qemu-log.c
@@ -25,17 +25,39 @@ static const char *logfilename = "qemu.log";
 #else
 static const char *logfilename = "/tmp/qemu.log";
 #endif
-FILE *logfile;
-int loglevel;
+FILE *qemu_logfile;
+int qemu_loglevel;
 static int log_append = 0;
 
+void qemu_log(const char *fmt, ...)
+{
+    va_list ap;
+
+    va_start(ap, fmt);
+    if (qemu_logfile) {
+        vfprintf(qemu_logfile, fmt, ap);
+    }
+    va_end(ap);
+}
+
+void qemu_log_mask(int mask, const char *fmt, ...)
+{
+    va_list ap;
+
+    va_start(ap, fmt);
+    if ((qemu_loglevel & mask) && qemu_logfile) {
+        vfprintf(qemu_logfile, fmt, ap);
+    }
+    va_end(ap);
+}
+
 /* enable or disable low levels log */
 void cpu_set_log(int log_flags)
 {
-    loglevel = log_flags;
-    if (loglevel && !logfile) {
-        logfile = fopen(logfilename, log_append ? "a" : "w");
-        if (!logfile) {
+    qemu_loglevel = log_flags;
+    if (qemu_loglevel && !qemu_logfile) {
+        qemu_logfile = fopen(logfilename, log_append ? "a" : "w");
+        if (!qemu_logfile) {
             perror(logfilename);
             _exit(1);
         }
@@ -43,30 +65,30 @@ void cpu_set_log(int log_flags)
         /* must avoid mmap() usage of glibc by setting a buffer "by hand" */
         {
             static char logfile_buf[4096];
-            setvbuf(logfile, logfile_buf, _IOLBF, sizeof(logfile_buf));
+            setvbuf(qemu_logfile, logfile_buf, _IOLBF, sizeof(logfile_buf));
         }
 #elif defined(_WIN32)
         /* Win32 doesn't support line-buffering, so use unbuffered output. */
-        setvbuf(logfile, NULL, _IONBF, 0);
+        setvbuf(qemu_logfile, NULL, _IONBF, 0);
 #else
-        setvbuf(logfile, NULL, _IOLBF, 0);
+        setvbuf(qemu_logfile, NULL, _IOLBF, 0);
 #endif
         log_append = 1;
     }
-    if (!loglevel && logfile) {
-        fclose(logfile);
-        logfile = NULL;
+    if (!qemu_loglevel && qemu_logfile) {
+        fclose(qemu_logfile);
+        qemu_logfile = NULL;
     }
 }
 
 void cpu_set_log_filename(const char *filename)
 {
     logfilename = strdup(filename);
-    if (logfile) {
-        fclose(logfile);
-        logfile = NULL;
+    if (qemu_logfile) {
+        fclose(qemu_logfile);
+        qemu_logfile = NULL;
     }
-    cpu_set_log(loglevel);
+    cpu_set_log(qemu_loglevel);
 }
 
 const CPULogItem cpu_log_items[] = {
diff --git a/qemu-log.h b/qemu-log.h
index e04ee9a..d1e0f2d 100644
--- a/qemu-log.h
+++ b/qemu-log.h
@@ -1,9 +1,14 @@
 #ifndef QEMU_LOG_H
 #define QEMU_LOG_H
 
-/* The deprecated global variables: */
-extern FILE *logfile;
-extern int loglevel;
+#include <stdarg.h>
+#ifdef NEED_CPU_H
+#include "disas.h"
+#endif
+
+/* Private global variables, don't use */
+extern FILE *qemu_logfile;
+extern int qemu_loglevel;
 
 /* 
  * The new API:
@@ -14,7 +19,10 @@ extern int loglevel;
 
 /* Returns true if qemu_log() will really write somewhere
  */
-#define qemu_log_enabled() (logfile != NULL)
+static inline bool qemu_log_enabled(void)
+{
+    return qemu_logfile != NULL;
+}
 
 #define CPU_LOG_TB_OUT_ASM (1 << 0)
 #define CPU_LOG_TB_IN_ASM  (1 << 1)
@@ -29,71 +37,97 @@ extern int loglevel;
 
 /* Returns true if a bit is set in the current loglevel mask
  */
-#define qemu_loglevel_mask(b) ((loglevel & (b)) != 0)
+static inline bool qemu_loglevel_mask(int mask)
+{
+    return (qemu_loglevel & mask) != 0;
+}
 
 /* Logging functions: */
 
 /* main logging function
  */
-#define qemu_log(...) do {                 \
-        if (logfile)                       \
-            fprintf(logfile, ## __VA_ARGS__); \
-    } while (0)
+void GCC_FMT_ATTR(1, 2) qemu_log(const char *fmt, ...);
 
 /* vfprintf-like logging function
  */
-#define qemu_log_vprintf(fmt, va) do {     \
-        if (logfile)                       \
-            vfprintf(logfile, fmt, va);    \
-    } while (0)
+static inline void qemu_log_vprintf(const char *fmt, va_list va)
+{
+    if (qemu_logfile) {
+        vfprintf(qemu_logfile, fmt, va);
+    }
+}
 
 /* log only if a bit is set on the current loglevel mask
  */
-#define qemu_log_mask(b, ...) do {         \
-        if (loglevel & (b))                \
-            fprintf(logfile, ## __VA_ARGS__); \
-    } while (0)
+void GCC_FMT_ATTR(2, 3) qemu_log_mask(int mask, const char *fmt, ...);
 
 
 /* Special cases: */
 
+#ifdef NEED_CPU_H
 /* cpu_dump_state() logging functions: */
-#define log_cpu_state(env, f) cpu_dump_state((env), logfile, fprintf, (f));
-#define log_cpu_state_mask(b, env, f) do {           \
-      if (loglevel & (b)) log_cpu_state((env), (f)); \
-  } while (0)
-
-/* disas() and target_disas() to logfile: */
-#define log_target_disas(start, len, flags) \
-        target_disas(logfile, (start), (len), (flags))
-#define log_disas(start, len) \
-        disas(logfile, (start), (len))
-
+static inline void log_cpu_state(CPUArchState *env1, int flags)
+{
+    cpu_dump_state(env1, qemu_logfile, fprintf, flags);
+}
+
+static inline void log_cpu_state_mask(int mask, CPUArchState *env1, int flags)
+{
+    if (qemu_loglevel & mask) {
+        log_cpu_state(env1, flags);
+    }
+}
+
+/* disas() and target_disas() to qemu_logfile: */
+static inline void log_target_disas(target_ulong start, target_ulong len,
+                                    int flags)
+{
+    target_disas(qemu_logfile, start, len, flags);
+}
+
+static inline void log_disas(void *code, unsigned long size)
+{
+    disas(qemu_logfile, code, size);
+}
+
+#if defined(CONFIG_USER_ONLY)
 /* page_dump() output to the log file: */
-#define log_page_dump() page_dump(logfile)
+static inline void log_page_dump(void)
+{
+    page_dump(qemu_logfile);
+}
+#endif
+#endif
 
 
 /* Maintenance: */
 
 /* fflush() the log file */
-#define qemu_log_flush() fflush(logfile)
+static inline void qemu_log_flush(void)
+{
+    fflush(qemu_logfile);
+}
 
 /* Close the log file */
-#define qemu_log_close() do { \
-        fclose(logfile);      \
-        logfile = NULL;       \
-    } while (0)
+static inline void qemu_log_close(void)
+{
+    fclose(qemu_logfile);
+    qemu_logfile = NULL;
+}
 
 /* Set up a new log file */
-#define qemu_log_set_file(f) do { \
-        logfile = (f);            \
-    } while (0)
+static inline void qemu_log_set_file(FILE *f)
+{
+    qemu_logfile = f;
+}
 
 /* Set up a new log file, only if none is set */
-#define qemu_log_try_set_file(f) do { \
-        if (!logfile)                 \
-            logfile = (f);            \
-    } while (0)
+static inline void qemu_log_try_set_file(FILE *f)
+{
+    if (!qemu_logfile) {
+        qemu_logfile = f;
+    }
+}
 
 /* define log items */
 typedef struct CPULogItem {
diff --git a/qemu-tool.c b/qemu-tool.c
index 07fc4f2..318c5fc 100644
--- a/qemu-tool.c
+++ b/qemu-tool.c
@@ -24,8 +24,6 @@
 
 #include <sys/time.h>
 
-FILE *logfile;
-
 struct QEMUBH
 {
     QEMUBHFunc *cb;
diff --git a/tcg/tcg.c b/tcg/tcg.c
index ab589c7..8386b70 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -873,7 +873,7 @@ static const char * const cond_name[] =
     [TCG_COND_GTU] = "gtu"
 };
 
-void tcg_dump_ops(TCGContext *s, FILE *outfile)
+void tcg_dump_ops(TCGContext *s)
 {
     const uint16_t *opc_ptr;
     const TCGArg *args;
@@ -896,9 +896,10 @@ void tcg_dump_ops(TCGContext *s, FILE *outfile)
 #else
             pc = args[0];
 #endif
-            if (!first_insn) 
-                fprintf(outfile, "\n");
-            fprintf(outfile, " ---- 0x%" PRIx64, pc);
+            if (!first_insn) {
+                qemu_log("\n");
+            }
+            qemu_log(" ---- 0x%" PRIx64, pc);
             first_insn = 0;
             nb_oargs = def->nb_oargs;
             nb_iargs = def->nb_iargs;
@@ -912,28 +913,28 @@ void tcg_dump_ops(TCGContext *s, FILE *outfile)
             nb_iargs = arg & 0xffff;
             nb_cargs = def->nb_cargs;
 
-            fprintf(outfile, " %s ", def->name);
+            qemu_log(" %s ", def->name);
 
             /* function name */
-            fprintf(outfile, "%s",
-                    tcg_get_arg_str_idx(s, buf, sizeof(buf), args[nb_oargs + nb_iargs - 1]));
+            qemu_log("%s",
+                     tcg_get_arg_str_idx(s, buf, sizeof(buf),
+                                         args[nb_oargs + nb_iargs - 1]));
             /* flags */
-            fprintf(outfile, ",$0x%" TCG_PRIlx,
-                    args[nb_oargs + nb_iargs]);
+            qemu_log(",$0x%" TCG_PRIlx, args[nb_oargs + nb_iargs]);
             /* nb out args */
-            fprintf(outfile, ",$%d", nb_oargs);
+            qemu_log(",$%d", nb_oargs);
             for(i = 0; i < nb_oargs; i++) {
-                fprintf(outfile, ",");
-                fprintf(outfile, "%s",
-                        tcg_get_arg_str_idx(s, buf, sizeof(buf), args[i]));
+                qemu_log(",");
+                qemu_log("%s", tcg_get_arg_str_idx(s, buf, sizeof(buf),
+                                                   args[i]));
             }
             for(i = 0; i < (nb_iargs - 1); i++) {
-                fprintf(outfile, ",");
+                qemu_log(",");
                 if (args[nb_oargs + i] == TCG_CALL_DUMMY_ARG) {
-                    fprintf(outfile, "<dummy>");
+                    qemu_log("<dummy>");
                 } else {
-                    fprintf(outfile, "%s",
-                            tcg_get_arg_str_idx(s, buf, sizeof(buf), args[nb_oargs + i]));
+                    qemu_log("%s", tcg_get_arg_str_idx(s, buf, sizeof(buf),
+                                                       args[nb_oargs + i]));
                 }
             }
         } else if (c == INDEX_op_movi_i32 
@@ -947,20 +948,21 @@ void tcg_dump_ops(TCGContext *s, FILE *outfile)
             nb_oargs = def->nb_oargs;
             nb_iargs = def->nb_iargs;
             nb_cargs = def->nb_cargs;
-            fprintf(outfile, " %s %s,$", def->name, 
-                    tcg_get_arg_str_idx(s, buf, sizeof(buf), args[0]));
+            qemu_log(" %s %s,$", def->name,
+                     tcg_get_arg_str_idx(s, buf, sizeof(buf), args[0]));
             val = args[1];
             th = tcg_find_helper(s, val);
             if (th) {
-                fprintf(outfile, "%s", th->name);
+                qemu_log("%s", th->name);
             } else {
-                if (c == INDEX_op_movi_i32)
-                    fprintf(outfile, "0x%x", (uint32_t)val);
-                else
-                    fprintf(outfile, "0x%" PRIx64 , (uint64_t)val);
+                if (c == INDEX_op_movi_i32) {
+                    qemu_log("0x%x", (uint32_t)val);
+                } else {
+                    qemu_log("0x%" PRIx64 , (uint64_t)val);
+                }
             }
         } else {
-            fprintf(outfile, " %s ", def->name);
+            qemu_log(" %s ", def->name);
             if (c == INDEX_op_nopn) {
                 /* variable number of arguments */
                 nb_cargs = *args;
@@ -974,16 +976,18 @@ void tcg_dump_ops(TCGContext *s, FILE *outfile)
             
             k = 0;
             for(i = 0; i < nb_oargs; i++) {
-                if (k != 0)
-                    fprintf(outfile, ",");
-                fprintf(outfile, "%s",
-                        tcg_get_arg_str_idx(s, buf, sizeof(buf), args[k++]));
+                if (k != 0) {
+                    qemu_log(",");
+                }
+                qemu_log("%s", tcg_get_arg_str_idx(s, buf, sizeof(buf),
+                                                   args[k++]));
             }
             for(i = 0; i < nb_iargs; i++) {
-                if (k != 0)
-                    fprintf(outfile, ",");
-                fprintf(outfile, "%s",
-                        tcg_get_arg_str_idx(s, buf, sizeof(buf), args[k++]));
+                if (k != 0) {
+                    qemu_log(",");
+                }
+                qemu_log("%s", tcg_get_arg_str_idx(s, buf, sizeof(buf),
+                                                   args[k++]));
             }
             switch (c) {
             case INDEX_op_brcond_i32:
@@ -998,10 +1002,11 @@ void tcg_dump_ops(TCGContext *s, FILE *outfile)
 #elif TCG_TARGET_REG_BITS == 64
             case INDEX_op_setcond_i64:
 #endif
-                if (args[k] < ARRAY_SIZE(cond_name) && cond_name[args[k]])
-                    fprintf(outfile, ",%s", cond_name[args[k++]]);
-                else
-                    fprintf(outfile, ",$0x%" TCG_PRIlx, args[k++]);
+                if (args[k] < ARRAY_SIZE(cond_name) && cond_name[args[k]]) {
+                    qemu_log(",%s", cond_name[args[k++]]);
+                } else {
+                    qemu_log(",$0x%" TCG_PRIlx, args[k++]);
+                }
                 i = 1;
                 break;
             default:
@@ -1009,13 +1014,14 @@ void tcg_dump_ops(TCGContext *s, FILE *outfile)
                 break;
             }
             for(; i < nb_cargs; i++) {
-                if (k != 0)
-                    fprintf(outfile, ",");
+                if (k != 0) {
+                    qemu_log(",");
+                }
                 arg = args[k++];
-                fprintf(outfile, "$0x%" TCG_PRIlx, arg);
+                qemu_log("$0x%" TCG_PRIlx, arg);
             }
         }
-        fprintf(outfile, "\n");
+        qemu_log("\n");
         args += nb_iargs + nb_oargs + nb_cargs;
     }
 }
@@ -2048,7 +2054,7 @@ static inline int tcg_gen_code_common(TCGContext *s, uint8_t *gen_code_buf,
 #ifdef DEBUG_DISAS
     if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP))) {
         qemu_log("OP:\n");
-        tcg_dump_ops(s, logfile);
+        tcg_dump_ops(s);
         qemu_log("\n");
     }
 #endif
@@ -2069,7 +2075,7 @@ static inline int tcg_gen_code_common(TCGContext *s, uint8_t *gen_code_buf,
 #ifdef DEBUG_DISAS
     if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP_OPT))) {
         qemu_log("OP after liveness analysis:\n");
-        tcg_dump_ops(s, logfile);
+        tcg_dump_ops(s);
         qemu_log("\n");
     }
 #endif
diff --git a/tcg/tcg.h b/tcg/tcg.h
index a83bddd..d710694 100644
--- a/tcg/tcg.h
+++ b/tcg/tcg.h
@@ -571,7 +571,7 @@ TCGArg *tcg_optimize(TCGContext *s, uint16_t *tcg_opc_ptr, TCGArg *args,
 /* only used for debugging purposes */
 void tcg_register_helper(void *func, const char *name);
 const char *tcg_helper_get_name(TCGContext *s, void *func);
-void tcg_dump_ops(TCGContext *s, FILE *outfile);
+void tcg_dump_ops(TCGContext *s);
 
 void dump_ops(const uint16_t *opc_buf, const TCGArg *opparam_buf);
 TCGv_i32 tcg_const_i32(int32_t val);
diff --git a/tcg/tci/tcg-target.c b/tcg/tci/tcg-target.c
index 453f187..d0a368d 100644
--- a/tcg/tci/tcg-target.c
+++ b/tcg/tci/tcg-target.c
@@ -878,7 +878,7 @@ static void tcg_target_init(TCGContext *s)
 #if defined(CONFIG_DEBUG_TCG_INTERPRETER)
     const char *envval = getenv("DEBUG_TCG");
     if (envval) {
-        loglevel = strtol(envval, NULL, 0);
+        cpu_set_log(strtol(envval, NULL, 0));
     }
 #endif
 
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [Qemu-devel] [PATCH 3/6] qemu-log: add log category for unimplemented functionality
  2012-06-09 12:12 [Qemu-devel] [PATCH v2 0/6] Log unimplemented functionality Blue Swirl
  2012-06-09 12:12 ` [Qemu-devel] [PATCH 1/6] qemu-log: move logging to qemu-log.c Blue Swirl
  2012-06-09 12:12 ` [Qemu-devel] [PATCH 2/6] qemu-log: cleanup Blue Swirl
@ 2012-06-09 12:12 ` Blue Swirl
  2012-06-09 12:12 ` [Qemu-devel] [PATCH 4/6] qemu-log: use LOG_UNIMP for some target CPU cases Blue Swirl
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 14+ messages in thread
From: Blue Swirl @ 2012-06-09 12:12 UTC (permalink / raw)
  To: qemu-devel

Add new log category (LOG_UNIMP) for unimplemented functionality.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
 qemu-log.c |    2 ++
 qemu-log.h |    1 +
 2 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/qemu-log.c b/qemu-log.c
index 1dd3de4..1ec70e7 100644
--- a/qemu-log.c
+++ b/qemu-log.c
@@ -120,6 +120,8 @@ const CPULogItem cpu_log_items[] = {
     { CPU_LOG_IOPORT, "ioport",
       "show all i/o ports accesses" },
 #endif
+    { LOG_UNIMP, "unimp",
+      "log unimplemented functionality" },
     { 0, NULL, NULL },
 };
 
diff --git a/qemu-log.h b/qemu-log.h
index d1e0f2d..40f8b7b 100644
--- a/qemu-log.h
+++ b/qemu-log.h
@@ -34,6 +34,7 @@ static inline bool qemu_log_enabled(void)
 #define CPU_LOG_IOPORT     (1 << 7)
 #define CPU_LOG_TB_CPU     (1 << 8)
 #define CPU_LOG_RESET      (1 << 9)
+#define LOG_UNIMP          (1 << 10)
 
 /* Returns true if a bit is set in the current loglevel mask
  */
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [Qemu-devel] [PATCH 4/6] qemu-log: use LOG_UNIMP for some target CPU cases
  2012-06-09 12:12 [Qemu-devel] [PATCH v2 0/6] Log unimplemented functionality Blue Swirl
                   ` (2 preceding siblings ...)
  2012-06-09 12:12 ` [Qemu-devel] [PATCH 3/6] qemu-log: add log category for unimplemented functionality Blue Swirl
@ 2012-06-09 12:12 ` Blue Swirl
  2012-06-09 12:12 ` [Qemu-devel] [PATCH 5/6] fdc: use LOG_UNIMP logging Blue Swirl
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 14+ messages in thread
From: Blue Swirl @ 2012-06-09 12:12 UTC (permalink / raw)
  To: qemu-devel

Use LOG_UNIMP for some target CPU cases.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
Acked-by: Alexander Graf <agraf@suse.de>
---
 target-i386/op_helper.c       |    1 +
 target-microblaze/translate.c |   11 ++++--
 target-ppc/helper.c           |    2 +-
 target-s390x/translate.c      |    2 +-
 target-sparc/ldst_helper.c    |   80 ++++++++++++++++++++++++----------------
 5 files changed, 58 insertions(+), 38 deletions(-)

diff --git a/target-i386/op_helper.c b/target-i386/op_helper.c
index bc3b94e..2862ea4 100644
--- a/target-i386/op_helper.c
+++ b/target-i386/op_helper.c
@@ -3146,6 +3146,7 @@ void helper_rdpmc(void)
     helper_svm_check_intercept_param(SVM_EXIT_RDPMC, 0);
     
     /* currently unimplemented */
+    qemu_log_mask(LOG_UNIMP, "x86: unimplemented rdpmc\n");
     raise_exception_err(EXCP06_ILLOP, 0);
 }
 
diff --git a/target-microblaze/translate.c b/target-microblaze/translate.c
index c0a6bfd..7470149 100644
--- a/target-microblaze/translate.c
+++ b/target-microblaze/translate.c
@@ -1539,8 +1539,10 @@ static void dec_fpu(DisasContext *dc)
                                        cpu_R[dc->ra], cpu_R[dc->rb]);
                     break;
                 default:
-                    qemu_log ("unimplemented fcmp fpu_insn=%x pc=%x opc=%x\n",
-                              fpu_insn, dc->pc, dc->opcode);
+                    qemu_log_mask(LOG_UNIMP,
+                                  "unimplemented fcmp fpu_insn=%x pc=%x"
+                                  " opc=%x\n",
+                                  fpu_insn, dc->pc, dc->opcode);
                     dc->abort_at_next_insn = 1;
                     break;
             }
@@ -1568,8 +1570,9 @@ static void dec_fpu(DisasContext *dc)
             break;
 
         default:
-            qemu_log ("unimplemented FPU insn fpu_insn=%x pc=%x opc=%x\n",
-                      fpu_insn, dc->pc, dc->opcode);
+            qemu_log_mask(LOG_UNIMP, "unimplemented FPU insn fpu_insn=%x pc=%x"
+                          " opc=%x\n",
+                          fpu_insn, dc->pc, dc->opcode);
             dc->abort_at_next_insn = 1;
             break;
     }
diff --git a/target-ppc/helper.c b/target-ppc/helper.c
index f556f85..3f7d8a4 100644
--- a/target-ppc/helper.c
+++ b/target-ppc/helper.c
@@ -1621,7 +1621,7 @@ void dump_mmu(FILE *f, fprintf_function cpu_fprintf, CPUPPCState *env)
         break;
 #endif
     default:
-        cpu_fprintf(f, "%s: unimplemented\n", __func__);
+        qemu_log_mask(LOG_UNIMP, "%s: unimplemented\n", __func__);
     }
 }
 
diff --git a/target-s390x/translate.c b/target-s390x/translate.c
index 9bf8c38..1c1baf5 100644
--- a/target-s390x/translate.c
+++ b/target-s390x/translate.c
@@ -5098,7 +5098,7 @@ static void disas_s390_insn(DisasContext *s)
         disas_ed(s, op, r1, x2, b2, d2, r1b);
         break;
     default:
-        LOG_DISAS("unimplemented opcode 0x%x\n", opc);
+        qemu_log_mask(LOG_UNIMP, "unimplemented opcode 0x%x\n", opc);
         gen_illegal_opcode(s, ilc);
         break;
     }
diff --git a/target-sparc/ldst_helper.c b/target-sparc/ldst_helper.c
index efe5e70..9bec7a9 100644
--- a/target-sparc/ldst_helper.c
+++ b/target-sparc/ldst_helper.c
@@ -464,16 +464,18 @@ uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong addr, int asi, int size,
             if (size == 8) {
                 ret = env->mxccregs[3];
             } else {
-                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
-                             size);
+                qemu_log_mask(LOG_UNIMP,
+                              "%08x: unimplemented access size: %d\n", addr,
+                              size);
             }
             break;
         case 0x01c00a04: /* MXCC control register */
             if (size == 4) {
                 ret = env->mxccregs[3];
             } else {
-                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
-                             size);
+                qemu_log_mask(LOG_UNIMP,
+                              "%08x: unimplemented access size: %d\n", addr,
+                              size);
             }
             break;
         case 0x01c00c00: /* Module reset register */
@@ -481,21 +483,24 @@ uint64_t helper_ld_asi(CPUSPARCState *env, target_ulong addr, int asi, int size,
                 ret = env->mxccregs[5];
                 /* should we do something here? */
             } else {
-                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
-                             size);
+                qemu_log_mask(LOG_UNIMP,
+                              "%08x: unimplemented access size: %d\n", addr,
+                              size);
             }
             break;
         case 0x01c00f00: /* MBus port address register */
             if (size == 8) {
                 ret = env->mxccregs[7];
             } else {
-                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
-                             size);
+                qemu_log_mask(LOG_UNIMP,
+                              "%08x: unimplemented access size: %d\n", addr,
+                              size);
             }
             break;
         default:
-            DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr,
-                         size);
+            qemu_log_mask(LOG_UNIMP,
+                          "%08x: unimplemented address, size: %d\n", addr,
+                          size);
             break;
         }
         DPRINTF_MXCC("asi = %d, size = %d, sign = %d, "
@@ -719,40 +724,45 @@ void helper_st_asi(CPUSPARCState *env, target_ulong addr, uint64_t val, int asi,
             if (size == 8) {
                 env->mxccdata[0] = val;
             } else {
-                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
-                             size);
+                qemu_log_mask(LOG_UNIMP,
+                              "%08x: unimplemented access size: %d\n", addr,
+                              size);
             }
             break;
         case 0x01c00008: /* MXCC stream data register 1 */
             if (size == 8) {
                 env->mxccdata[1] = val;
             } else {
-                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
-                             size);
+                qemu_log_mask(LOG_UNIMP,
+                              "%08x: unimplemented access size: %d\n", addr,
+                              size);
             }
             break;
         case 0x01c00010: /* MXCC stream data register 2 */
             if (size == 8) {
                 env->mxccdata[2] = val;
             } else {
-                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
-                             size);
+                qemu_log_mask(LOG_UNIMP,
+                              "%08x: unimplemented access size: %d\n", addr,
+                              size);
             }
             break;
         case 0x01c00018: /* MXCC stream data register 3 */
             if (size == 8) {
                 env->mxccdata[3] = val;
             } else {
-                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
-                             size);
+                qemu_log_mask(LOG_UNIMP,
+                              "%08x: unimplemented access size: %d\n", addr,
+                              size);
             }
             break;
         case 0x01c00100: /* MXCC stream source */
             if (size == 8) {
                 env->mxccregs[0] = val;
             } else {
-                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
-                             size);
+                qemu_log_mask(LOG_UNIMP,
+                              "%08x: unimplemented access size: %d\n", addr,
+                              size);
             }
             env->mxccdata[0] = ldq_phys((env->mxccregs[0] & 0xffffffffULL) +
                                         0);
@@ -767,8 +777,9 @@ void helper_st_asi(CPUSPARCState *env, target_ulong addr, uint64_t val, int asi,
             if (size == 8) {
                 env->mxccregs[1] = val;
             } else {
-                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
-                             size);
+                qemu_log_mask(LOG_UNIMP,
+                              "%08x: unimplemented access size: %d\n", addr,
+                              size);
             }
             stq_phys((env->mxccregs[1] & 0xffffffffULL) +  0,
                      env->mxccdata[0]);
@@ -783,8 +794,9 @@ void helper_st_asi(CPUSPARCState *env, target_ulong addr, uint64_t val, int asi,
             if (size == 8) {
                 env->mxccregs[3] = val;
             } else {
-                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
-                             size);
+                qemu_log_mask(LOG_UNIMP,
+                              "%08x: unimplemented access size: %d\n", addr,
+                              size);
             }
             break;
         case 0x01c00a04: /* MXCC control register */
@@ -792,8 +804,9 @@ void helper_st_asi(CPUSPARCState *env, target_ulong addr, uint64_t val, int asi,
                 env->mxccregs[3] = (env->mxccregs[3] & 0xffffffff00000000ULL)
                     | val;
             } else {
-                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
-                             size);
+                qemu_log_mask(LOG_UNIMP,
+                              "%08x: unimplemented access size: %d\n", addr,
+                              size);
             }
             break;
         case 0x01c00e00: /* MXCC error register  */
@@ -801,21 +814,24 @@ void helper_st_asi(CPUSPARCState *env, target_ulong addr, uint64_t val, int asi,
             if (size == 8) {
                 env->mxccregs[6] &= ~val;
             } else {
-                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
-                             size);
+                qemu_log_mask(LOG_UNIMP,
+                              "%08x: unimplemented access size: %d\n", addr,
+                              size);
             }
             break;
         case 0x01c00f00: /* MBus port address register */
             if (size == 8) {
                 env->mxccregs[7] = val;
             } else {
-                DPRINTF_MXCC("%08x: unimplemented access size: %d\n", addr,
-                             size);
+                qemu_log_mask(LOG_UNIMP,
+                              "%08x: unimplemented access size: %d\n", addr,
+                              size);
             }
             break;
         default:
-            DPRINTF_MXCC("%08x: unimplemented address, size: %d\n", addr,
-                         size);
+            qemu_log_mask(LOG_UNIMP,
+                          "%08x: unimplemented address, size: %d\n", addr,
+                          size);
             break;
         }
         DPRINTF_MXCC("asi = %d, size = %d, addr = %08x, val = %" PRIx64 "\n",
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [Qemu-devel] [PATCH 5/6] fdc: use LOG_UNIMP logging
  2012-06-09 12:12 [Qemu-devel] [PATCH v2 0/6] Log unimplemented functionality Blue Swirl
                   ` (3 preceding siblings ...)
  2012-06-09 12:12 ` [Qemu-devel] [PATCH 4/6] qemu-log: use LOG_UNIMP for some target CPU cases Blue Swirl
@ 2012-06-09 12:12 ` Blue Swirl
  2012-06-11 13:09   ` Kevin Wolf
  2012-06-09 12:12 ` [Qemu-devel] [PATCH 6/6] qtest: add a fuzz test to fdc-test Blue Swirl
  2012-06-09 13:14 ` [Qemu-devel] [PATCH v2 0/6] Log unimplemented functionality Andreas Färber
  6 siblings, 1 reply; 14+ messages in thread
From: Blue Swirl @ 2012-06-09 12:12 UTC (permalink / raw)
  To: qemu-devel

Convert uses of FLOPPY_ERROR to either FLOPPY_DPRINTF
(for implemented cases) or to use LOG_UNIMP (unimplemented).

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
 hw/fdc.c |   30 +++++++++++++++++-------------
 1 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/hw/fdc.c b/hw/fdc.c
index 30d34e3..6625fcb 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -36,6 +36,7 @@
 #include "qdev-addr.h"
 #include "blockdev.h"
 #include "sysemu.h"
+#include "qemu-log.h"
 
 /********************************************************/
 /* debug Floppy devices */
@@ -48,9 +49,6 @@
 #define FLOPPY_DPRINTF(fmt, ...)
 #endif
 
-#define FLOPPY_ERROR(fmt, ...)                                          \
-    do { printf("FLOPPY ERROR: %s: " fmt, __func__ , ## __VA_ARGS__); } while (0)
-
 /********************************************************/
 /* Floppy drive emulation                               */
 
@@ -147,8 +145,10 @@ static int fd_seek(FDrive *drv, uint8_t head, uint8_t track, uint8_t sect,
     if (sector != fd_sector(drv)) {
 #if 0
         if (!enable_seek) {
-            FLOPPY_ERROR("no implicit seek %d %02x %02x (max=%d %02x %02x)\n",
-                         head, track, sect, 1, drv->max_track, drv->last_sect);
+            FLOPPY_DPRINTF("error: no implicit seek %d %02x %02x"
+                           " (max=%d %02x %02x)\n",
+                           head, track, sect, 1, drv->max_track,
+                           drv->last_sect);
             return 4;
         }
 #endif
@@ -987,7 +987,8 @@ static void fdctrl_set_fifo(FDCtrl *fdctrl, int fifo_len, int do_irq)
 /* Set an error: unimplemented/unknown command */
 static void fdctrl_unimplemented(FDCtrl *fdctrl, int direction)
 {
-    FLOPPY_ERROR("unimplemented command 0x%02x\n", fdctrl->fifo[0]);
+    qemu_log_mask(LOG_UNIMP, "fdc: unimplemented command 0x%02x\n",
+                  fdctrl->fifo[0]);
     fdctrl->fifo[0] = FD_SR0_INVCMD;
     fdctrl_set_fifo(fdctrl, 1, 0);
 }
@@ -1155,7 +1156,8 @@ static void fdctrl_start_transfer(FDCtrl *fdctrl, int direction)
             DMA_schedule(fdctrl->dma_chann);
             return;
         } else {
-            FLOPPY_ERROR("dma_mode=%d direction=%d\n", dma_mode, direction);
+            FLOPPY_DPRINTF("bad dma_mode=%d direction=%d\n", dma_mode,
+                           direction);
         }
     }
     FLOPPY_DPRINTF("start non-DMA transfer\n");
@@ -1171,7 +1173,7 @@ static void fdctrl_start_transfer(FDCtrl *fdctrl, int direction)
 /* Prepare a transfer of deleted data */
 static void fdctrl_start_transfer_del(FDCtrl *fdctrl, int direction)
 {
-    FLOPPY_ERROR("fdctrl_start_transfer_del() unimplemented\n");
+    qemu_log_mask(LOG_UNIMP, "fdctrl_start_transfer_del() unimplemented\n");
 
     /* We don't handle deleted data,
      * so we don't return *ANYTHING*
@@ -1250,7 +1252,8 @@ static int fdctrl_transfer_handler (void *opaque, int nchan,
                              fdctrl->data_pos, len);
             if (bdrv_write(cur_drv->bs, fd_sector(cur_drv),
                            fdctrl->fifo, 1) < 0) {
-                FLOPPY_ERROR("writing sector %d\n", fd_sector(cur_drv));
+                FLOPPY_DPRINTF("error writing sector %d\n",
+                               fd_sector(cur_drv));
                 fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00);
                 goto transfer_error;
             }
@@ -1309,7 +1312,7 @@ static uint32_t fdctrl_read_data(FDCtrl *fdctrl)
     cur_drv = get_cur_drv(fdctrl);
     fdctrl->dsr &= ~FD_DSR_PWRDOWN;
     if (!(fdctrl->msr & FD_MSR_RQM) || !(fdctrl->msr & FD_MSR_DIO)) {
-        FLOPPY_ERROR("controller not ready for reading\n");
+        FLOPPY_DPRINTF("error: controller not ready for reading\n");
         return 0;
     }
     pos = fdctrl->data_pos;
@@ -1393,7 +1396,7 @@ static void fdctrl_format_sector(FDCtrl *fdctrl)
     memset(fdctrl->fifo, 0, FD_SECTOR_LEN);
     if (cur_drv->bs == NULL ||
         bdrv_write(cur_drv->bs, fd_sector(cur_drv), fdctrl->fifo, 1) < 0) {
-        FLOPPY_ERROR("formatting sector %d\n", fd_sector(cur_drv));
+        FLOPPY_DPRINTF("error formatting sector %d\n", fd_sector(cur_drv));
         fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00);
     } else {
         if (cur_drv->sect == cur_drv->last_sect) {
@@ -1768,7 +1771,7 @@ static void fdctrl_write_data(FDCtrl *fdctrl, uint32_t value)
         return;
     }
     if (!(fdctrl->msr & FD_MSR_RQM) || (fdctrl->msr & FD_MSR_DIO)) {
-        FLOPPY_ERROR("controller not ready for writing\n");
+        FLOPPY_DPRINTF("error: controller not ready for writing\n");
         return;
     }
     fdctrl->dsr &= ~FD_DSR_PWRDOWN;
@@ -1782,7 +1785,8 @@ static void fdctrl_write_data(FDCtrl *fdctrl, uint32_t value)
             fdctrl->data_pos == fdctrl->data_len) {
             cur_drv = get_cur_drv(fdctrl);
             if (bdrv_write(cur_drv->bs, fd_sector(cur_drv), fdctrl->fifo, 1) < 0) {
-                FLOPPY_ERROR("writing sector %d\n", fd_sector(cur_drv));
+                FLOPPY_DPRINTF("error writing sector %d\n",
+                               fd_sector(cur_drv));
                 return;
             }
             if (!fdctrl_seek_to_next_sect(fdctrl, cur_drv)) {
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [Qemu-devel] [PATCH 6/6] qtest: add a fuzz test to fdc-test
  2012-06-09 12:12 [Qemu-devel] [PATCH v2 0/6] Log unimplemented functionality Blue Swirl
                   ` (4 preceding siblings ...)
  2012-06-09 12:12 ` [Qemu-devel] [PATCH 5/6] fdc: use LOG_UNIMP logging Blue Swirl
@ 2012-06-09 12:12 ` Blue Swirl
  2012-06-09 13:14 ` [Qemu-devel] [PATCH v2 0/6] Log unimplemented functionality Andreas Färber
  6 siblings, 0 replies; 14+ messages in thread
From: Blue Swirl @ 2012-06-09 12:12 UTC (permalink / raw)
  To: qemu-devel

Add a simple register fuzzing test to floppy controller tests.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
 tests/fdc-test.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/tests/fdc-test.c b/tests/fdc-test.c
index 22d24ac..676b215 100644
--- a/tests/fdc-test.c
+++ b/tests/fdc-test.c
@@ -185,6 +185,22 @@ static void test_media_change(void)
     assert_bit_set(dir, DSKCHG);
 }
 
+/* success if no crash or abort */
+static void fuzz_registers(void)
+{
+    unsigned int i;
+
+    for (i = 0; i < 1000; i++) {
+        uint8_t reg, val;
+
+        reg = (uint8_t)g_test_rand_int_range(0, 8);
+        val = (uint8_t)g_test_rand_int_range(0, 256);
+
+        outb(FLOPPY_BASE + reg, val);
+        inb(FLOPPY_BASE + reg);
+    }
+}
+
 int main(int argc, char **argv)
 {
     const char *arch = qtest_get_arch();
@@ -215,6 +231,7 @@ int main(int argc, char **argv)
     qtest_add_func("/fdc/cmos", test_cmos);
     qtest_add_func("/fdc/no_media_on_start", test_no_media_on_start);
     qtest_add_func("/fdc/media_change", test_media_change);
+    qtest_add_func("/fdc/fuzz-registers", fuzz_registers);
 
     ret = g_test_run();
 
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [Qemu-devel] [PATCH v2 0/6] Log unimplemented functionality
  2012-06-09 12:12 [Qemu-devel] [PATCH v2 0/6] Log unimplemented functionality Blue Swirl
                   ` (5 preceding siblings ...)
  2012-06-09 12:12 ` [Qemu-devel] [PATCH 6/6] qtest: add a fuzz test to fdc-test Blue Swirl
@ 2012-06-09 13:14 ` Andreas Färber
  6 siblings, 0 replies; 14+ messages in thread
From: Andreas Färber @ 2012-06-09 13:14 UTC (permalink / raw)
  To: Blue Swirl; +Cc: qemu-devel

Am 09.06.2012 14:12, schrieb Blue Swirl:
> v2: address Kevin's comments to 5/6
> 
> Blue Swirl (6):
>   qemu-log: move logging to qemu-log.c
>   qemu-log: cleanup
>   qemu-log: add log category for unimplemented functionality
>   qemu-log: use LOG_UNIMP for some target CPU cases
>   fdc: use LOG_UNIMP logging
>   qtest: add a fuzz test to fdc-test

Series arrived threaded and git-am was happy, thanks a lot!
Also compiles fine, didn't test further.

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Qemu-devel] [PATCH 5/6] fdc: use LOG_UNIMP logging
  2012-06-09 12:12 ` [Qemu-devel] [PATCH 5/6] fdc: use LOG_UNIMP logging Blue Swirl
@ 2012-06-11 13:09   ` Kevin Wolf
  0 siblings, 0 replies; 14+ messages in thread
From: Kevin Wolf @ 2012-06-11 13:09 UTC (permalink / raw)
  To: Blue Swirl; +Cc: qemu-devel

Am 09.06.2012 14:12, schrieb Blue Swirl:
> Convert uses of FLOPPY_ERROR to either FLOPPY_DPRINTF
> (for implemented cases) or to use LOG_UNIMP (unimplemented).
> 
> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>

Acked-by: Kevin Wolf <kwolf@redhat.com>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Qemu-devel] [PATCH 1/6] qemu-log: move logging to qemu-log.c
  2012-06-09 12:12 ` [Qemu-devel] [PATCH 1/6] qemu-log: move logging to qemu-log.c Blue Swirl
@ 2012-07-03 10:07   ` Kevin Wolf
  2012-07-03 19:19     ` Blue Swirl
  0 siblings, 1 reply; 14+ messages in thread
From: Kevin Wolf @ 2012-07-03 10:07 UTC (permalink / raw)
  To: Blue Swirl; +Cc: qemu-devel

Am 09.06.2012 14:12, schrieb Blue Swirl:
> Move logging functions from exec.c to qemu-log.c,
> compile it only once.
> 
> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>

This broke the TARGET_I386 specific logging options.

Kevin

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Qemu-devel] [PATCH 1/6] qemu-log: move logging to qemu-log.c
  2012-07-03 10:07   ` Kevin Wolf
@ 2012-07-03 19:19     ` Blue Swirl
  2012-07-04  8:34       ` Kevin Wolf
  0 siblings, 1 reply; 14+ messages in thread
From: Blue Swirl @ 2012-07-03 19:19 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: qemu-devel

On Tue, Jul 3, 2012 at 10:07 AM, Kevin Wolf <kwolf@redhat.com> wrote:
> Am 09.06.2012 14:12, schrieb Blue Swirl:
>> Move logging functions from exec.c to qemu-log.c,
>> compile it only once.
>>
>> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
>
> This broke the TARGET_I386 specific logging options.

Also DEBUG_IOPORT. Maybe  the logger should be compiled for each
target, but that does not look attractive.

>
> Kevin

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Qemu-devel] [PATCH 1/6] qemu-log: move logging to qemu-log.c
  2012-07-03 19:19     ` Blue Swirl
@ 2012-07-04  8:34       ` Kevin Wolf
  2012-07-05 18:07         ` Blue Swirl
  0 siblings, 1 reply; 14+ messages in thread
From: Kevin Wolf @ 2012-07-04  8:34 UTC (permalink / raw)
  To: Blue Swirl; +Cc: qemu-devel

Am 03.07.2012 21:19, schrieb Blue Swirl:
> On Tue, Jul 3, 2012 at 10:07 AM, Kevin Wolf <kwolf@redhat.com> wrote:
>> Am 09.06.2012 14:12, schrieb Blue Swirl:
>>> Move logging functions from exec.c to qemu-log.c,
>>> compile it only once.
>>>
>>> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
>>
>> This broke the TARGET_I386 specific logging options.
> 
> Also DEBUG_IOPORT. Maybe  the logger should be compiled for each
> target, but that does not look attractive.

The options that I see are more or less:

1. Compile the file for each target
2. Move only cpu_log_items[] to a separately compiled file
3. Replace the #ifdef by a runtime check

Kevin

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Qemu-devel] [PATCH 1/6] qemu-log: move logging to qemu-log.c
  2012-07-04  8:34       ` Kevin Wolf
@ 2012-07-05 18:07         ` Blue Swirl
  2012-07-06  9:14           ` Kevin Wolf
  0 siblings, 1 reply; 14+ messages in thread
From: Blue Swirl @ 2012-07-05 18:07 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: qemu-devel

On Wed, Jul 4, 2012 at 8:34 AM, Kevin Wolf <kwolf@redhat.com> wrote:
> Am 03.07.2012 21:19, schrieb Blue Swirl:
>> On Tue, Jul 3, 2012 at 10:07 AM, Kevin Wolf <kwolf@redhat.com> wrote:
>>> Am 09.06.2012 14:12, schrieb Blue Swirl:
>>>> Move logging functions from exec.c to qemu-log.c,
>>>> compile it only once.
>>>>
>>>> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
>>>
>>> This broke the TARGET_I386 specific logging options.
>>
>> Also DEBUG_IOPORT. Maybe  the logger should be compiled for each
>> target, but that does not look attractive.
>
> The options that I see are more or less:
>
> 1. Compile the file for each target
> 2. Move only cpu_log_items[] to a separately compiled file
> 3. Replace the #ifdef by a runtime check

I think we could just remove #ifdeffery and adjust the text with
"(x86)", for example
 "show protected mode far calls/returns/exceptions (x86 only)"

It should be safe to enable all options, obviously some of them won't
do anything if enabled for the wrong architecture.

>
> Kevin

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Qemu-devel] [PATCH 1/6] qemu-log: move logging to qemu-log.c
  2012-07-05 18:07         ` Blue Swirl
@ 2012-07-06  9:14           ` Kevin Wolf
  0 siblings, 0 replies; 14+ messages in thread
From: Kevin Wolf @ 2012-07-06  9:14 UTC (permalink / raw)
  To: Blue Swirl; +Cc: qemu-devel

Am 05.07.2012 20:07, schrieb Blue Swirl:
> On Wed, Jul 4, 2012 at 8:34 AM, Kevin Wolf <kwolf@redhat.com> wrote:
>> Am 03.07.2012 21:19, schrieb Blue Swirl:
>>> On Tue, Jul 3, 2012 at 10:07 AM, Kevin Wolf <kwolf@redhat.com> wrote:
>>>> Am 09.06.2012 14:12, schrieb Blue Swirl:
>>>>> Move logging functions from exec.c to qemu-log.c,
>>>>> compile it only once.
>>>>>
>>>>> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
>>>>
>>>> This broke the TARGET_I386 specific logging options.
>>>
>>> Also DEBUG_IOPORT. Maybe  the logger should be compiled for each
>>> target, but that does not look attractive.
>>
>> The options that I see are more or less:
>>
>> 1. Compile the file for each target
>> 2. Move only cpu_log_items[] to a separately compiled file
>> 3. Replace the #ifdef by a runtime check
> 
> I think we could just remove #ifdeffery and adjust the text with
> "(x86)", for example
>  "show protected mode far calls/returns/exceptions (x86 only)"
> 
> It should be safe to enable all options, obviously some of them won't
> do anything if enabled for the wrong architecture.

Right, should be good enough indeed.

Kevin

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2012-07-06  9:14 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-09 12:12 [Qemu-devel] [PATCH v2 0/6] Log unimplemented functionality Blue Swirl
2012-06-09 12:12 ` [Qemu-devel] [PATCH 1/6] qemu-log: move logging to qemu-log.c Blue Swirl
2012-07-03 10:07   ` Kevin Wolf
2012-07-03 19:19     ` Blue Swirl
2012-07-04  8:34       ` Kevin Wolf
2012-07-05 18:07         ` Blue Swirl
2012-07-06  9:14           ` Kevin Wolf
2012-06-09 12:12 ` [Qemu-devel] [PATCH 2/6] qemu-log: cleanup Blue Swirl
2012-06-09 12:12 ` [Qemu-devel] [PATCH 3/6] qemu-log: add log category for unimplemented functionality Blue Swirl
2012-06-09 12:12 ` [Qemu-devel] [PATCH 4/6] qemu-log: use LOG_UNIMP for some target CPU cases Blue Swirl
2012-06-09 12:12 ` [Qemu-devel] [PATCH 5/6] fdc: use LOG_UNIMP logging Blue Swirl
2012-06-11 13:09   ` Kevin Wolf
2012-06-09 12:12 ` [Qemu-devel] [PATCH 6/6] qtest: add a fuzz test to fdc-test Blue Swirl
2012-06-09 13:14 ` [Qemu-devel] [PATCH v2 0/6] Log unimplemented functionality Andreas Färber

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.