]> git.proxmox.com Git - qemu.git/blobdiff - qemu-log.c
qemu-log: Abstract out "print usage message about valid log categories"
[qemu.git] / qemu-log.c
index 1ec70e7e83644368bf158943c105ad02f755cb9b..786d3358931a3fae34b35e81e469cc986670c51c 100644 (file)
  */
 
 #include "qemu-common.h"
-#include "qemu-log.h"
+#include "qemu/log.h"
 
 #ifdef WIN32
-static const char *logfilename = "qemu.log";
+#define DEFAULT_LOGFILENAME "qemu.log"
 #else
-static const char *logfilename = "/tmp/qemu.log";
+#define DEFAULT_LOGFILENAME "/tmp/qemu.log"
 #endif
+
+static char *logfilename;
 FILE *qemu_logfile;
 int qemu_loglevel;
 static int log_append = 0;
@@ -52,28 +54,31 @@ void qemu_log_mask(int mask, const char *fmt, ...)
 }
 
 /* enable or disable low levels log */
-void cpu_set_log(int log_flags)
+void qemu_set_log(int log_flags, bool use_own_buffers)
 {
+    const char *fname = logfilename ?: DEFAULT_LOGFILENAME;
+
     qemu_loglevel = log_flags;
     if (qemu_loglevel && !qemu_logfile) {
-        qemu_logfile = fopen(logfilename, log_append ? "a" : "w");
+        qemu_logfile = fopen(fname, log_append ? "a" : "w");
         if (!qemu_logfile) {
-            perror(logfilename);
+            perror(fname);
             _exit(1);
         }
-#if !defined(CONFIG_SOFTMMU)
         /* must avoid mmap() usage of glibc by setting a buffer "by hand" */
-        {
+        if (use_own_buffers) {
             static char logfile_buf[4096];
+
             setvbuf(qemu_logfile, logfile_buf, _IOLBF, sizeof(logfile_buf));
-        }
-#elif defined(_WIN32)
-        /* Win32 doesn't support line-buffering, so use unbuffered output. */
-        setvbuf(qemu_logfile, NULL, _IONBF, 0);
+        } else {
+#if defined(_WIN32)
+            /* Win32 doesn't support line-buffering, so use unbuffered output. */
+            setvbuf(qemu_logfile, NULL, _IONBF, 0);
 #else
-        setvbuf(qemu_logfile, NULL, _IOLBF, 0);
+            setvbuf(qemu_logfile, NULL, _IOLBF, 0);
 #endif
-        log_append = 1;
+            log_append = 1;
+        }
     }
     if (!qemu_loglevel && qemu_logfile) {
         fclose(qemu_logfile);
@@ -81,9 +86,10 @@ void cpu_set_log(int log_flags)
     }
 }
 
-void cpu_set_log_filename(const char *filename)
+void qemu_set_log_filename(const char *filename)
 {
-    logfilename = strdup(filename);
+    g_free(logfilename);
+    logfilename = g_strdup(filename);
     if (qemu_logfile) {
         fclose(qemu_logfile);
         qemu_logfile = NULL;
@@ -99,10 +105,7 @@ const CPULogItem cpu_log_items[] = {
     { 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
+      "show micro ops (x86 only: before eflags optimization) and\n"
       "after liveness analysis" },
     { CPU_LOG_INT, "int",
       "show interrupts/exceptions in short format" },
@@ -110,18 +113,17 @@ const CPULogItem cpu_log_items[] = {
       "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" },
+      "x86 only: show protected mode far calls/returns/exceptions" },
     { CPU_LOG_RESET, "cpu_reset",
-      "show CPU state before CPU resets" },
-#endif
-#ifdef DEBUG_IOPORT
+      "x86 only: show CPU state before CPU resets" },
     { CPU_LOG_IOPORT, "ioport",
       "show all i/o ports accesses" },
-#endif
     { LOG_UNIMP, "unimp",
       "log unimplemented functionality" },
+    { LOG_GUEST_ERROR, "guest_errors",
+      "log when the guest OS does something invalid (eg accessing a\n"
+      "non-existent register)" },
     { 0, NULL, NULL },
 };
 
@@ -168,3 +170,12 @@ int cpu_str_to_log_mask(const char *str)
     }
     return mask;
 }
+
+void qemu_print_log_usage(FILE *f)
+{
+    const CPULogItem *item;
+    fprintf(f, "Log items (comma separated):\n");
+    for (item = cpu_log_items; item->mask != 0; item++) {
+        fprintf(f, "%-10s %s\n", item->name, item->help);
+    }
+}