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: 2170471 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id E77923FD4E for ; Thu, 21 Feb 2013 04:25:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751392Ab3BUEZk (ORCPT ); Wed, 20 Feb 2013 23:25:40 -0500 Received: from cantor2.suse.de ([195.135.220.15]:49377 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751266Ab3BUEZk (ORCPT ); Wed, 20 Feb 2013 23:25:40 -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 Cc: =?UTF-8?q?Andreas=20F=C3=A4rber?= , Richard Henderson , Gleb Natapov (supporter:X86), Marcelo Tosatti (supporter:X86), kvm@vger.kernel.org (open list:X86) Subject: [PATCH v2 08/15] target-i386: Refactor debug output macros 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 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.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)