From patchwork Sat Jun 9 12:12:40 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Blue Swirl X-Patchwork-Id: 163915 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 13C5FB6FBD for ; Sat, 9 Jun 2012 22:13:16 +1000 (EST) Received: from localhost ([::1]:50741 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SdKXZ-0007y8-Ps for incoming@patchwork.ozlabs.org; Sat, 09 Jun 2012 08:13:13 -0400 Received: from eggs.gnu.org ([208.118.235.92]:36493) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SdKXC-0007gv-UH for qemu-devel@nongnu.org; Sat, 09 Jun 2012 08:12:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SdKXA-0002sz-6e for qemu-devel@nongnu.org; Sat, 09 Jun 2012 08:12:50 -0400 Received: from mail-ey0-f173.google.com ([209.85.215.173]:62767) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SdKX9-0002se-Qh for qemu-devel@nongnu.org; Sat, 09 Jun 2012 08:12:48 -0400 Received: by eaak12 with SMTP id k12so1736008eaa.4 for ; Sat, 09 Jun 2012 05:12:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:x-mailer:in-reply-to:references :in-reply-to:references; bh=ng+C9Z2kTPjH9qxPyXrWzwKXlmOnD76C3QQCC9owrJo=; b=X7z9CUj4OAnQ+WjIpFNMltv63m1Nfi3NLDe7HHbIQyBy0qDcetc/r6JUagAPmIh6zo Wn0Ah9LphTftU5fAEC2TLJSFynuZVA4REsNR6uSvwOLpv0GngVV0DKDMW4Z93GYF2t4o DYoi69Hd5OwcZFQ75t1RUa3d5i3z39u1GuIf+hfiCBHfK35ZuOQO7EEPKAS6XxMGKD5h xYyWTNCQFxQ/rJJc9yGqmCEGD9ijWkEHUtby1KNrVHDSOzR71fDPi1fM3q5r4NiPO9gN p0JANddexwpWsJR/NPsTUpmikuubd4seaJSId4xsmtpwlO7WR40lpgGhpi9npbvdijPG zDzg== Received: by 10.14.101.136 with SMTP id b8mr4905492eeg.100.1339243965692; Sat, 09 Jun 2012 05:12:45 -0700 (PDT) Received: from localhost.localdomain (blueswirl.broker.freenet6.net. [2001:5c0:1400:b::d5a3]) by mx.google.com with ESMTPS id c51sm31917591eei.12.2012.06.09.05.12.44 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 09 Jun 2012 05:12:45 -0700 (PDT) From: Blue Swirl To: qemu-devel@nongnu.org Date: Sat, 9 Jun 2012 12:12:40 +0000 Message-Id: X-Mailer: git-send-email 1.7.2.5 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.215.173 Subject: [Qemu-devel] [PATCH 1/6] qemu-log: move logging to qemu-log.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Move logging functions from exec.c to qemu-log.c, compile it only once. Signed-off-by: Blue Swirl --- 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 . + */ + +#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