X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=qemu-log.c;h=797f2af983aef24021c7ea51f79eaa628a51e2c9;hb=54e755588cf1e90f0b1460c4e8e6b6a54b6d3a32;hp=1ec70e7e83644368bf158943c105ad02f755cb9b;hpb=959a255dfbe085a47e00fd21c57e87ad4c92719e;p=qemu.git diff --git a/qemu-log.c b/qemu-log.c index 1ec70e7e8..797f2af98 100644 --- a/qemu-log.c +++ b/qemu-log.c @@ -18,13 +18,9 @@ */ #include "qemu-common.h" -#include "qemu-log.h" +#include "qemu/log.h" -#ifdef WIN32 -static const char *logfilename = "qemu.log"; -#else -static const char *logfilename = "/tmp/qemu.log"; -#endif +static char *logfilename; FILE *qemu_logfile; int qemu_loglevel; static int log_append = 0; @@ -52,46 +48,49 @@ void qemu_log_mask(int mask, const char *fmt, ...) } /* enable or disable low levels log */ -void cpu_set_log(int log_flags) +void do_qemu_set_log(int log_flags, bool use_own_buffers) { qemu_loglevel = log_flags; if (qemu_loglevel && !qemu_logfile) { - qemu_logfile = fopen(logfilename, log_append ? "a" : "w"); - if (!qemu_logfile) { - perror(logfilename); - _exit(1); + if (logfilename) { + qemu_logfile = fopen(logfilename, log_append ? "a" : "w"); + if (!qemu_logfile) { + perror(logfilename); + _exit(1); + } + } else { + /* Default to stderr if no log file specified */ + qemu_logfile = stderr; } -#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); - qemu_logfile = NULL; + qemu_log_close(); } } -void cpu_set_log_filename(const char *filename) +void qemu_set_log_filename(const char *filename) { - logfilename = strdup(filename); - if (qemu_logfile) { - fclose(qemu_logfile); - qemu_logfile = NULL; - } - cpu_set_log(qemu_loglevel); + g_free(logfilename); + logfilename = g_strdup(filename); + qemu_log_close(); + qemu_set_log(qemu_loglevel); } -const CPULogItem cpu_log_items[] = { +const QEMULogItem qemu_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", @@ -99,10 +98,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 +106,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 }, }; @@ -134,9 +129,9 @@ static int cmp1(const char *s1, int n, const char *s2) } /* takes a comma separated list of log masks. Return 0 if error. */ -int cpu_str_to_log_mask(const char *str) +int qemu_str_to_log_mask(const char *str) { - const CPULogItem *item; + const QEMULogItem *item; int mask; const char *p, *p1; @@ -148,11 +143,11 @@ int cpu_str_to_log_mask(const char *str) p1 = p + strlen(p); } if (cmp1(p,p1-p,"all")) { - for (item = cpu_log_items; item->mask != 0; item++) { + for (item = qemu_log_items; item->mask != 0; item++) { mask |= item->mask; } } else { - for (item = cpu_log_items; item->mask != 0; item++) { + for (item = qemu_log_items; item->mask != 0; item++) { if (cmp1(p, p1 - p, item->name)) { goto found; } @@ -168,3 +163,12 @@ int cpu_str_to_log_mask(const char *str) } return mask; } + +void qemu_print_log_usage(FILE *f) +{ + const QEMULogItem *item; + fprintf(f, "Log items (comma separated):\n"); + for (item = qemu_log_items; item->mask != 0; item++) { + fprintf(f, "%-10s %s\n", item->name, item->help); + } +}