Make debug output compile-testable even if disabled. Introduce DPRINTF() in helper.c and consolidate stdout and stderr output. Introduce DPRINTF() in mmu.c and inline remaining D(x).
Drop unused D(x) macros in op_helper.c and translate.c. Signed-off-by: Andreas Färber <afaer...@suse.de> --- target-cris/helper.c | 32 ++++++++++++++++++----- target-cris/mmu.c | 66 ++++++++++++++++++++++++++++++----------------- target-cris/op_helper.c | 16 +++++++++--- target-cris/translate.c | 23 +++++++++-------- 4 Dateien geändert, 92 Zeilen hinzugefügt(+), 45 Zeilen entfernt(-) diff --git a/target-cris/helper.c b/target-cris/helper.c index de04143..2ddaebb 100644 --- a/target-cris/helper.c +++ b/target-cris/helper.c @@ -27,11 +27,31 @@ #ifdef CRIS_HELPER_DEBUG -#define D(x) x -#define D_LOG(...) qemu_log(__VA_ARGS__) +static const bool debug_helper = true; #else -#define D(x) -#define D_LOG(...) do { } while (0) +static const bool debug_helper; +#endif + +#ifndef CONFIG_USER_ONLY +static void GCC_FMT_ATTR(1, 2) D_LOG(const char *fmt, ...) +{ + if (debug_helper) { + va_list ap; + va_start(ap, fmt); + qemu_log_vprintf(fmt, ap); + va_end(ap); + } +} + +static void GCC_FMT_ATTR(1, 2) DPRINTF(const char *fmt, ...) +{ + if (debug_helper) { + va_list ap; + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + } +} #endif #if defined(CONFIG_USER_ONLY) @@ -71,7 +91,7 @@ int cpu_cris_handle_mmu_fault(CPUCRISState *env, target_ulong address, int rw, int r = -1; target_ulong phy; - D(printf("%s addr=%x pc=%x rw=%x\n", __func__, address, env->pc, rw)); + DPRINTF("%s addr=%x pc=%x rw=%x\n", __func__, address, env->pc, rw); miss = cris_mmu_translate(&res, env, address & TARGET_PAGE_MASK, rw, mmu_idx, 0); if (miss) { @@ -259,7 +279,7 @@ hwaddr cpu_get_phys_page_debug(CPUCRISState * env, target_ulong addr) if (!miss) { phy = res.phy; } - D(fprintf(stderr, "%s %x -> %x\n", __func__, addr, phy)); + DPRINTF("%s %x -> %x\n", __func__, addr, phy); return phy; } #endif diff --git a/target-cris/mmu.c b/target-cris/mmu.c index ee31e2a..9f98e0d 100644 --- a/target-cris/mmu.c +++ b/target-cris/mmu.c @@ -24,13 +24,31 @@ #include "mmu.h" #ifdef DEBUG -#define D(x) x -#define D_LOG(...) qemu_log(__VA_ARGS__) +static const bool debug_mmu = true; #else -#define D(x) do { } while (0) -#define D_LOG(...) do { } while (0) +static const bool debug_mmu; #endif +static void GCC_FMT_ATTR(1, 2) DPRINTF(const char *fmt, ...) +{ + if (debug_mmu) { + va_list ap; + va_start(ap, fmt); + vprintf(fmt, ap); + va_end(ap); + } +} + +static void GCC_FMT_ATTR(1, 2) D_LOG(const char *fmt, ...) +{ + if (debug_mmu) { + va_list ap; + va_start(ap, fmt); + qemu_log_vprintf(fmt, ap); + va_end(ap); + } +} + void cris_mmu_init(CPUCRISState *env) { env->mmu_rand_lfsr = 0xcccc; @@ -105,7 +123,6 @@ static inline void set_field(uint32_t *dst, unsigned int val, *dst |= val; } -#ifdef DEBUG static void dump_tlb(CPUCRISState *env, int mmu) { int set; @@ -124,7 +141,6 @@ static void dump_tlb(CPUCRISState *env, int mmu) } } } -#endif /* rw 0 = read, 1 = write, 2 = exec. */ static int cris_mmu_translate_page(struct cris_mmu_result *res, @@ -225,23 +241,23 @@ static int cris_mmu_translate_page(struct cris_mmu_result *res, set_exception_vector(0x0b, d_mmu_write); */ if (cfg_k && tlb_k && usermode) { - D(printf("tlb: kernel protected %x lo=%x pc=%x\n", - vaddr, lo, env->pc)); + DPRINTF("tlb: kernel protected %x lo=%x pc=%x\n", + vaddr, lo, env->pc); match = 0; res->bf_vec = vect_base + 2; } else if (rw == 1 && cfg_w && !tlb_w) { - D(printf("tlb: write protected %x lo=%x pc=%x\n", - vaddr, lo, env->pc)); + DPRINTF("tlb: write protected %x lo=%x pc=%x\n", + vaddr, lo, env->pc); match = 0; /* write accesses never go through the I mmu. */ res->bf_vec = vect_base + 3; } else if (rw == 2 && cfg_x && !tlb_x) { - D(printf("tlb: exec protected %x lo=%x pc=%x\n", - vaddr, lo, env->pc)); + DPRINTF("tlb: exec protected %x lo=%x pc=%x\n", + vaddr, lo, env->pc); match = 0; res->bf_vec = vect_base + 3; } else if (cfg_v && !tlb_v) { - D(printf("tlb: invalid %x\n", vaddr)); + DPRINTF("tlb: invalid %x\n", vaddr); match = 0; res->bf_vec = vect_base + 1; } @@ -256,7 +272,9 @@ static int cris_mmu_translate_page(struct cris_mmu_result *res, res->prot |= PAGE_EXEC; } } else { - D(dump_tlb(env, mmu)); + if (debug_mmu) { + dump_tlb(env, mmu); + } } } else { /* If refill, provide a randomized set. */ @@ -279,18 +297,18 @@ static int cris_mmu_translate_page(struct cris_mmu_result *res, set_field(&r_cause, vpage, 13, 19); set_field(&r_cause, pid, 0, 8); env->sregs[SFR_R_MM_CAUSE] = r_cause; - D(printf("refill vaddr=%x pc=%x\n", vaddr, env->pc)); + DPRINTF("refill vaddr=%x pc=%x\n", vaddr, env->pc); } - D(printf("%s rw=%d mtch=%d pc=%x va=%x vpn=%x tlbvpn=%x pfn=%x pid=%x" - " %x cause=%x sel=%x sp=%x %x %x\n", - __func__, rw, match, env->pc, - vaddr, vpage, - tlb_vpn, tlb_pfn, tlb_pid, - pid, - r_cause, - env->sregs[SFR_RW_MM_TLB_SEL], - env->regs[R_SP], env->pregs[PR_USP], env->ksp)); + DPRINTF("%s rw=%d mtch=%d pc=%x va=%x vpn=%x tlbvpn=%x pfn=%x pid=%x" + " %x cause=%x sel=%x sp=%x %x %x\n", + __func__, rw, match, env->pc, + vaddr, vpage, + tlb_vpn, tlb_pfn, tlb_pid, + pid, + r_cause, + env->sregs[SFR_RW_MM_TLB_SEL], + env->regs[R_SP], env->pregs[PR_USP], env->ksp); res->phy = tlb_pfn << TARGET_PAGE_BITS; return !match; diff --git a/target-cris/op_helper.c b/target-cris/op_helper.c index b580513..47f7c64 100644 --- a/target-cris/op_helper.c +++ b/target-cris/op_helper.c @@ -27,13 +27,21 @@ #ifdef CRIS_OP_HELPER_DEBUG -#define D(x) x -#define D_LOG(...) qemu_log(__VA_ARGS__) +static const bool debug_op_helper = true; #else -#define D(x) -#define D_LOG(...) do { } while (0) +static const bool debug_op_helper; #endif +static void GCC_FMT_ATTR(1, 2) D_LOG(const char *fmt, ...) +{ + if (debug_op_helper) { + va_list ap; + va_start(ap, fmt); + qemu_log_vprintf(fmt, ap); + va_end(ap); + } +} + #if !defined(CONFIG_USER_ONLY) #include "exec/softmmu_exec.h" diff --git a/target-cris/translate.c b/target-cris/translate.c index 04a5379..8e53253 100644 --- a/target-cris/translate.c +++ b/target-cris/translate.c @@ -35,12 +35,21 @@ #define DISAS_CRIS 0 #if DISAS_CRIS -# define LOG_DIS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__) +static const bool debug_disas = true; #else -# define LOG_DIS(...) do { } while (0) +static const bool debug_disas; #endif -#define D(x) +static void GCC_FMT_ATTR(1, 2) LOG_DIS(const char *fmt, ...) +{ + if (debug_disas) { + va_list ap; + va_start(ap, fmt); + qemu_log_mask_vprintf(CPU_LOG_TB_IN_ASM, fmt, ap); + va_end(ap); + } +} + #define BUG() (gen_BUG(dc, __FILE__, __LINE__)) #define BUG_ON(x) ({if (x) BUG();}) @@ -1263,7 +1272,6 @@ static inline void t_gen_zext(TCGv d, TCGv s, int size) } } -#if DISAS_CRIS static char memsize_char(int size) { switch (size) { @@ -1275,7 +1283,6 @@ static char memsize_char(int size) break; } } -#endif static inline unsigned int memsize_z(DisasContext *dc) { @@ -1370,7 +1377,6 @@ static int dec_prep_alu_m(CPUCRISState *env, DisasContext *dc, return insn_len; } -#if DISAS_CRIS static const char *cc_name(int cc) { static const char *cc_names[16] = { @@ -1380,7 +1386,6 @@ static const char *cc_name(int cc) assert(cc < 16); return cc_names[cc]; } -#endif /* Start of insn decoders. */ @@ -1842,7 +1847,6 @@ static int dec_mcp_r(CPUCRISState *env, DisasContext *dc) return 2; } -#if DISAS_CRIS static char * swapmode_name(int mode, char *modename) { int i = 0; if (mode & 8) { @@ -1860,14 +1864,11 @@ static char * swapmode_name(int mode, char *modename) { modename[i++] = 0; return modename; } -#endif static int dec_swap_r(CPUCRISState *env, DisasContext *dc) { TCGv t0; -#if DISAS_CRIS char modename[4]; -#endif LOG_DIS("swap%s $r%u\n", swapmode_name(dc->op2, modename), dc->op1); -- 1.7.10.4