From patchwork Thu Feb 21 04:25:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 222180 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 453AF2C0090 for ; Thu, 21 Feb 2013 16:08:26 +1100 (EST) Received: from localhost ([::1]:47064 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U8Njn-0000NE-Kf for incoming@patchwork.ozlabs.org; Wed, 20 Feb 2013 23:26:27 -0500 Received: from eggs.gnu.org ([208.118.235.92]:34213) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U8Nj3-00072M-Rv for qemu-devel@nongnu.org; Wed, 20 Feb 2013 23:25:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U8Nj0-0002CK-7y for qemu-devel@nongnu.org; Wed, 20 Feb 2013 23:25:41 -0500 Received: from cantor2.suse.de ([195.135.220.15]:49376 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U8Niz-0002C7-UP for qemu-devel@nongnu.org; Wed, 20 Feb 2013 23:25:38 -0500 Received: from relay1.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 54FB5A51F5; Thu, 21 Feb 2013 05:25:37 +0100 (CET) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Thu, 21 Feb 2013 05:25:04 +0100 Message-Id: <1361420711-15698-9-git-send-email-afaerber@suse.de> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1361420711-15698-1-git-send-email-afaerber@suse.de> References: <1361420711-15698-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 195.135.220.15 Cc: "open list:X86" , Marcelo Tosatti , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Gleb Natapov , Richard Henderson Subject: [Qemu-devel] [PATCH v2 08/15] target-i386: Refactor debug output macros 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 Make debug output compile-testable even if disabled. Signed-off-by: Andreas Färber Cc: Richard Henderson --- target-i386/helper.c | 42 ++++++++++++++++++++++++++---------------- target-i386/kvm.c | 16 ++++++++++++---- target-i386/seg_helper.c | 24 +++++++++++++++++++----- 3 Dateien geändert, 57 Zeilen hinzugefügt(+), 25 Zeilen entfernt(-) diff --git a/target-i386/helper.c b/target-i386/helper.c index 4bf9db7..696e4e1 100644 --- a/target-i386/helper.c +++ b/target-i386/helper.c @@ -26,6 +26,22 @@ //#define DEBUG_MMU +#ifdef DEBUG_MMU +static const bool debug_mmu = true; +#else +static const bool debug_mmu; +#endif + +static void GCC_FMT_ATTR(1, 2) mmu_dprintf(const char *fmt, ...) +{ + if (debug_mmu) { + va_list ap; + va_start(ap, fmt); + vprintf(fmt, ap); + va_end(ap); + } +} + static void cpu_x86_version(CPUX86State *env, int *family, int *model) { int cpuver = env->cpuid_version; @@ -372,9 +388,8 @@ void x86_cpu_set_a20(X86CPU *cpu, int a20_state) a20_state = (a20_state != 0); if (a20_state != ((env->a20_mask >> 20) & 1)) { -#if defined(DEBUG_MMU) - printf("A20 update: a20=%d\n", a20_state); -#endif + mmu_dprintf("A20 update: a20=%d\n", a20_state); + /* if the cpu is currently executing code, we must unlink it and all the potentially executing TB */ cpu_interrupt(env, CPU_INTERRUPT_EXITTB); @@ -390,9 +405,8 @@ void cpu_x86_update_cr0(CPUX86State *env, uint32_t new_cr0) { int pe_state; -#if defined(DEBUG_MMU) - printf("CR0 update: CR0=0x%08x\n", new_cr0); -#endif + mmu_dprintf("CR0 update: CR0=0x%08x\n", new_cr0); + if ((new_cr0 & (CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK)) != (env->cr[0] & (CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK))) { tlb_flush(env, 1); @@ -433,18 +447,15 @@ void cpu_x86_update_cr3(CPUX86State *env, target_ulong new_cr3) { env->cr[3] = new_cr3; if (env->cr[0] & CR0_PG_MASK) { -#if defined(DEBUG_MMU) - printf("CR3 update: CR3=" TARGET_FMT_lx "\n", new_cr3); -#endif + mmu_dprintf("CR3 update: CR3=" TARGET_FMT_lx "\n", new_cr3); tlb_flush(env, 0); } } void cpu_x86_update_cr4(CPUX86State *env, uint32_t new_cr4) { -#if defined(DEBUG_MMU) - printf("CR4 update: CR4=%08x\n", (uint32_t)env->cr[4]); -#endif + mmu_dprintf("CR4 update: CR4=%08x\n", (uint32_t)env->cr[4]); + if ((new_cr4 ^ env->cr[4]) & (CR4_PGE_MASK | CR4_PAE_MASK | CR4_PSE_MASK | CR4_SMEP_MASK | CR4_SMAP_MASK)) { @@ -510,10 +521,9 @@ int cpu_x86_handle_mmu_fault(CPUX86State *env, target_ulong addr, target_ulong vaddr, virt_addr; is_user = mmu_idx == MMU_USER_IDX; -#if defined(DEBUG_MMU) - printf("MMU fault: addr=" TARGET_FMT_lx " w=%d u=%d eip=" TARGET_FMT_lx "\n", - addr, is_write1, is_user, env->eip); -#endif + mmu_dprintf("MMU fault: addr=" TARGET_FMT_lx " w=%d u=%d" + " eip=" TARGET_FMT_lx "\n", + addr, is_write1, is_user, env->eip); is_write = is_write1 & 1; if (!(env->cr[0] & CR0_PG_MASK)) { diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 0cf413d..9cbef77 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -37,13 +37,21 @@ //#define DEBUG_KVM #ifdef DEBUG_KVM -#define DPRINTF(fmt, ...) \ - do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0) +static const bool debug_kvm = true; #else -#define DPRINTF(fmt, ...) \ - do { } while (0) +static const bool debug_kvm; #endif +static void GCC_FMT_ATTR(1, 2) DPRINTF(const char *fmt, ...) +{ + if (debug_kvm) { + va_list ap; + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + } +} + #define MSR_KVM_WALL_CLOCK 0x11 #define MSR_KVM_SYSTEM_TIME 0x12 diff --git a/target-i386/seg_helper.c b/target-i386/seg_helper.c index 3247dee..2338d54 100644 --- a/target-i386/seg_helper.c +++ b/target-i386/seg_helper.c @@ -29,14 +29,28 @@ #endif /* !defined(CONFIG_USER_ONLY) */ #ifdef DEBUG_PCALL -# define LOG_PCALL(...) qemu_log_mask(CPU_LOG_PCALL, ## __VA_ARGS__) -# define LOG_PCALL_STATE(env) \ - log_cpu_state_mask(CPU_LOG_PCALL, (env), CPU_DUMP_CCOP) +static const bool debug_pcall = true; #else -# define LOG_PCALL(...) do { } while (0) -# define LOG_PCALL_STATE(env) do { } while (0) +static const bool debug_pcall; #endif +static void GCC_FMT_ATTR(1, 2) LOG_PCALL(const char *fmt, ...) +{ + if (debug_pcall) { + va_list ap; + va_start(ap, fmt); + qemu_log_mask(CPU_LOG_PCALL, fmt, ap); + va_end(ap); + } +} + +static inline void LOG_PCALL_STATE(CPUX86State *env) +{ + if (debug_pcall) { + log_cpu_state_mask(CPU_LOG_PCALL, (env), CPU_DUMP_CCOP); + } +} + /* return non zero if error */ static inline int load_segment(CPUX86State *env, uint32_t *e1_ptr, uint32_t *e2_ptr, int selector)